2

I want to print different size lists side by side.

I'm using

In: for n,g in zip(ten_pos,real_pos):
        print (n + "\t\t\t\t\t\t" + g)

But If one list has 5 item and the other one has 20, It only prints 5 and 5 and I want 5 and 20.

Is there an easy way to solve this?

Yared J.
  • 231
  • 1
  • 2
  • 9
  • Then use `itertools.izip_longest`. There's probably a dupe for this already. searching . . . – Moses Koledoye Jul 20 '16 at 20:40
  • 1
    Also [Zipping unequal lists in python in to a list which does not drop any element from longer list being zipped](http://stackoverflow.com/questions/11318977/zipping-unequal-lists-in-python-in-to-a-list-which-does-not-drop-any-element-fro) – Moses Koledoye Jul 20 '16 at 20:42

1 Answers1

3

Check out itertools.zip_longest.

import itertools

for a, b in itertools.zip_longest([1,2], [3,4,5]):
    print(a, b)

# outputs
1 3
2 4
None 5

You can change the value used to fill with the kwarg fillvalue.

Alex
  • 18,484
  • 8
  • 60
  • 80