mylist = [int(x) for x in '3 ,2 ,6 '.split(',')]
And if you’re not sure you’ll only have digits (or want to discard the others):
mylist = [int(x) for x in '3 ,2 ,6 '.split(',') if x.strip().isdigit()]
More Related Contents:
- The letter ‘n’ is invalid syntax in Python? [closed]
- How to remove items from a list while iterating?
- Python subprocess readlines() hangs
- Text progress bar in terminal with block characters [closed]
- “ssl module in Python is not available” when installing package with pip3
- How to specify multiple return types using type-hints
- Writing Unicode text to a text file?
- pandas dataframe str.contains() AND operation
- Grouping / clustering numbers in Python
- Most efficient property to hash for numpy array
- re.findall not returning full match?
- How to use Win32 API with Python?
- Difference between exit(0) and exit(1) in Python
- Why can’t you add attributes to object in python? [duplicate]
- SSL: CERTIFICATE_VERIFY_FAILED with Python3
- How can a function access its own attributes?
- Python Compilation/Interpretation Process
- Cancellable threading.Timer in Python
- from __future__ import annotations
- How to redirect stderr in Python?
- What’s the best solution for OpenID with Django? [closed]
- Where are the python modules stored?
- Two’s Complement Binary in Python?
- When to cache a DataFrame?
- Upper case first letter of each word in a phrase
- Why does a python module act like a singleton?
- Python IMAP search using a subject encoded with utf-8
- Delete an uploaded file after downloading it from Flask
- Creating a Menu in Python [closed]
- Pythonic/efficient way to strip whitespace from every Pandas Data frame cell that has a stringlike object in it