Using unpacking:
[*my_lst[:2], set(my_lst[2:])]
Output:
['a', 'b', {'c', 'd', 'e', 'f', 'g'}]
You can make the last element as a whole string with str
:
[*my_lst[:2], str(set(my_lst[2:]))]
Output:
['a', 'b', "{'f', 'd', 'e', 'c', 'g'}"]
More Related Contents:
- Finding the average from user given list in python [closed]
- Pandas: Drop consecutive duplicates
- BeautifulSoup getting href [duplicate]
- Importing files from different folder
- How to add percentages on top of bars in seaborn
- Is there an easy way to pickle a python function (or otherwise serialize its code)?
- Get a function argument’s default value?
- Nested SSH using Python Paramiko
- Pandas filling missing dates and values within group
- pandas unique values multiple columns
- Python parsing bracketed blocks
- How do I write good/correct package __init__.py files
- Django Local Settings
- Refresh Excel External Data with Python
- Python Run a daemon sub-process & read stdout
- How to use chrome webdriver in selenium to download files in python?
- problems with pygame controller support
- Python pandas / matplotlib annotating labels above bar chart columns [duplicate]
- error installing nltk supporting packages : nltk.download()
- Python code to read registry
- UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd1 in position 2: ordinal not in range(128)
- multiprocessing pool example does not work and freeze the kernel
- ‘virtualenv’ is not recognized as an internal or external command, operable program or batch file
- Checking if a website is up via Python
- Write a Pandas DataFrame to Google Cloud Storage or BigQuery
- Weighted random sample without replacement in python
- Python find list lengths in a sublist
- How to execute a script remotely in Python using SSH?
- What’s the difference between a module and package in Python?
- Plotting a 3d cube, a sphere and a vector