Python - convert string to list

0 votes

i have a string like this :

states = "Alaska Alabama Arkansas American Samoa Arizona California Colorado"

and I want to split it into a list like this

states = {Alaska, Alabama, Arkansas, American, Samoa, ....}

I am new in python.

Help me please. :-))

Jul 20, 2018 in Python by eatcodesleeprepeat
• 4,720 points
85 views

1 answer to this question.

0 votes

try states.split()

this would help.

answered Jul 20, 2018 by Priyaj
• 57,300 points

Related Questions In Python

0 votes
1 answer

Python - convert string to list

states.split() will return ['Alaska', 'Alabama', 'Arkansas', 'American', 'Samoa', ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,810 points
66 views
+1 vote
5 answers

convert string to int python

Using list comprehensions: t2 = [map(int, list(l)) for ...READ MORE

answered Oct 18, 2018 in Python by donald
97 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 57,300 points
75 views
0 votes
1 answer

How to convert date string to date object in python?

Use this :-  >>> datetime.datetime.strptime('24052010 ...READ MORE

answered Oct 22, 2018 in Python by Priyaj
• 57,300 points
401 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 425 views
+1 vote
2 answers

How to convert list to string

mylist = [1, 2, 3] ‘’.join(map(str, mylist)) ==> ...READ MORE

answered Aug 21, 2018 in Python by Omkar
• 68,480 points
57 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 57,300 points
660 views