0

I want to use a list comprehension to achieve the same results as below. Can anyone help?

s1 = "one two three four"
s2 = "five six seven eight"

my_list = []
l1 = s1.split()
l2 = s2.split()
my_list.append(l1)
my_list.append(l2)

print(my_list)

It outputs:

[['one', 'two', 'three', 'four'], ['five', 'six', 'seven', 'eight']]
Neil
  • 706
  • 8
  • 23

1 Answers1

0

use a list of all the strings you want as

lst_of_s = [s1,s2,s3]

result = [i.split() for i in lst_of_s]
rawwar
  • 4,834
  • 9
  • 32
  • 57