-1

i have,

list1 = [1, 2, 3, 4, 5]
list2 = [7, 8, 9, 14, 25, 36]
list3 = [43, 65]

and what i want to achieve is

1 7 43
2 8 65
3 9
4 14
5 25
  36

i have tried looking in methods like itertools and multiprocessiongbut none of them helps,

is there a way i can achiver this in a single for loop like...

for I, J, K inb list1, list2, list3:
    print('{} {} {}'.format(I, J, K))

any help?

EDIT

zip function gets the least number of elements from the lists, if i use zip the output will be

1 7 43
2 8 65
P.hunter
  • 1,345
  • 2
  • 21
  • 45

1 Answers1

0

You can try this using itertools:

import itertools

list1 = [1, 2, 3, 4, 5]
list2 = [7, 8, 9, 14, 25, 36]
list3 = [43, 65]

for a, b, c in itertools.izip_longest(list1, list2, list3):
     print a, b, c
Ajax1234
  • 69,937
  • 8
  • 61
  • 102