-4

What I want to do is convert a string like:

    "77 65 84"

To a list like:

    ["77", "65", "84"]

I tried the list() function but it does not work.

explorer
  • 31
  • 1
  • 6

3 Answers3

0

Use the split() method of strings.

nosklo
  • 217,122
  • 57
  • 293
  • 297
0

Use .split()

test_str = "77 65 84"
test_list = test_str.split()

for i in test_list:
  print(i)

So after .split() test_list[0]=77 , test_list[1]=65 etc..

NBlaine
  • 493
  • 2
  • 11
0

Use split()

>>> my_string = "77 65 84"
>>> my_list = my_string.split()
>>> my_list
['77', '65', '84']

You can do the same thing by specifying the separator, like so:

>>> comma_string = "74,65,84"
>>> comma_list = comma_string.split(",")
>>> comma_list
['74', '65', '84']
localghost
  • 329
  • 1
  • 4
  • 11