How to convert String to list in Python 3

marzymster

After user input, variable colors = "58, 234, 209", it is string. I need to convert it to list - colors = [58, 234, 209]. Which way I can do it. Thank you.

color = ("Enter color you like, something like that 58, 234, 209. ")
colors = input(color)
Pi Marillion

Since you have some non-space characters in there like ,, you'll want to use a flexible splitter, like re.split:

import re
colors = input('Enter color you like, something like that 58, 234, 209. ')
colors = list(map(int, re.split(r'[^\d]+', colors)))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Python 3 - How to convert a string to a list of dictionary

How to convert a list of string numbers into int number in Python3?

Convert List to String and back to List Python 3

How to convert list of string to list of dictionary in Python

How to convert String("ed") list to list in python

How to convert a string of a list into a list in Python?

Convert a string to a list of numbers in python 3

Python 3, how to convert a 2D list saved as a string into a list

How to convert list which contains a single string with multiple entries inside of string. Python 3

How to convert a string list to integer in python?

How to convert multiple string in one list python

How to convert python text string to List?

How to convert string to list in python. Like "['a']" to ['a']

How to convert list of string dates to datetime in python

How to convert a string into list with one element in python

Python: how to convert a string array to a factor list

How to convert a complex list to string in Python?

How to convert String values in a dictionary to a list in python?

How to convert list of string to dictionary in python

how to convert list of dictionary into string python

How to convert string with numeric range into a list in Python

how to convert list of unicode url to string in python

How to use python to convert a string to a list?

How to convert a Python string in a list using no libraries

convert list to string in python

Python: convert string to list

Python:- Convert a string into list

Python – Convert string to list

How to convert byte to string in python 3?