-1

What is the best way to convert a list from string on the format ['1,2,3,4'] to a list [1, 2, 3, 4]? The string may also be empty [''], in which case the conversion should return an empty list [].

  • Split your string into a list a strings `yourlist = yourvar[0].split(',')`, then use map to iterate through the elements and convert them into integers, `result = list(map(lambda x: int(x), yourlist))`. You should get the list of integers you needed. – Marco Jun 03 '22 at 15:08

0 Answers0