0

I am trying to convert a string such as '239,24,6462,93' to a list like ['239', '24', '6462', '93'] as sort of an opposite of str.join() . Is there anything that can do that? All help appreciated.

Martin Hallén
  • 1,492
  • 1
  • 12
  • 27
jath03
  • 2,029
  • 2
  • 14
  • 20

2 Answers2

1

Lets say this string is called "str".

str='239,24,6462,93';

Now to get these numbers into a list you can type the following:

numbers=str.split(",")

Output

['239', '24', '6462', '93']
cssGEEK
  • 994
  • 2
  • 15
  • 38
  • Why are you using the word list in this example? I thought you should never use the names of Python built-ins as variable names. – PyNEwbie Jun 19 '16 at 19:38
  • sorry my bad you can stil use that name but it is not good practice – cssGEEK Jun 19 '16 at 19:39
-1
>>> '239,24,6462,93'.split(",")
['239', '24', '6462', '93']
Martin Hallén
  • 1,492
  • 1
  • 12
  • 27