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)
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.
Comments