0

Is it possible in Python to convert a raw string divided by commas, e.g.

tt0099700,tt0096061,tt0118688,tt0120784

into a Python array/list?

Such string is in loop as a variable row[i].

Thanks for any help.

nnnmmm
  • 7,964
  • 4
  • 22
  • 41
b36
  • 105
  • 1
  • 8
  • 4
    Use [`split`](https://docs.python.org/3.7/library/stdtypes.html#str.split) – zvone May 04 '19 at 13:58
  • Possible duplicate of [Python import csv to list](https://stackoverflow.com/questions/24662571/python-import-csv-to-list) – Gino Mempin May 04 '19 at 14:03
  • 1
    Possible duplicate of [Split a string by a delimiter in python](https://stackoverflow.com/questions/3475251/split-a-string-by-a-delimiter-in-python) – Boris Verkhovskiy May 04 '19 at 14:11

1 Answers1

5

Try:

input_list = 'tt0099700,tt0096061,tt0118688,tt0120784'
new_list = input_list.split(',')

Output of new_list:

['tt0099700', 'tt0096061', 'tt0118688', 'tt0120784']
Mark Moretto
  • 2,344
  • 2
  • 15
  • 21