0

To create list from sentence is what I want to do. Firstly, what I have done is coordinating this sentence,data = "In many countries food manufacturers are required by" to list like

lines = data.split(' ')

and got

['In','many','countries','food','manufacturers','are','required','by']

Then, I want to change this form to

([('In','many'),('countries','food'),('manufacturers','are'),('required','by')])

How should I do next ? I would appreciate if you teach me in detail.

martineau
  • 119,623
  • 25
  • 170
  • 301
TIshow
  • 918
  • 4
  • 12
  • 27

2 Answers2

3
 d=[(lines[i],lines[i+1]) for i in range(0,len(lines)-1,2)]
 print d
akp
  • 619
  • 5
  • 12
1
data = "In many countries food manufacturers are required by"
lines = data.split(' ')
print([(lines[i], lines[i+1]) for i in range(0, len(lines)-1, 2)])