-3

My code is as follows:

for row in lineReader:
        i=i+1
        if i<3:
          tweet = row[0] 
          label = row[1]

          train = [tweet, label]
          print train

Output: ['tweet0', 'label0'] ['tweet1', 'label1']

Expected Output:

[('tweet0', 'label0'), ('tweet1', 'label1')]

Any suggestions on how to get the expected output?

Ashwin
  • 83
  • 10
  • Thanks for the response! I need to retain the tuples inside the list and not just concatenate the lists. – Ashwin Apr 11 '16 at 17:17
  • @Ashwin Maybe you should edit your question and be more specific about what it is you are looking to do? Also, you need to show your own coding attempt at this and explain what is currently not working in your current approach. – idjaw Apr 11 '16 at 17:18
  • @Ashwin: what makes you think concatenating will do anything to the tuples? `lst1, lst2 = [('text0', 'label0')], [('text1', 'label1')]; lst1 + lst2` produces your expected output. – Martijn Pieters Apr 11 '16 at 17:24
  • Yes, I tried this but i have only one variable: train = [('text0', 'label0')], [('text1', 'label1')] – Ashwin Apr 11 '16 at 17:31
  • If you want a list of these tuples, then define a variable `trains` before the for loop and change the last but one line to: `trains.append([tweet, label])`. Then, `trains` will have the list of tuples. – trans1st0r Apr 11 '16 at 18:03

1 Answers1

0

list1 + list2 would do the trick

Ragnarok
  • 170
  • 14