0

I have the following two lists:

nums = [1, 2, 3, 4, 5, 6, 7, 8]

ltrs = ['a', 'b', 'c', 'd']

I would like for the output to be:

1, a, 2, b, 3, c, 4, d, 5, 6, 7, 8

I have tried both:

for x in nums:
    for y in ltrs:
        print(x, Y)

for x, y in zip(nums, ltrs):
    print(x, y)

Neither produce the output I am looking for as the ZIP method provided as answer for other similar questions, does not work in my case because, as far as I know, ZIP does not work when the lists are of different length.

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
I.T. Guy
  • 111
  • 1
  • 10
  • The answer provided for that question does not work in this case, as you can see I tried the 'zip' method - not what I'm looking to do. – I.T. Guy Oct 04 '17 at 15:08
  • Using `zip`, and `str()` for the numbers, build up a list of strings which alternate between the two, then print `', '.join(the_list)` – John Coleman Oct 04 '17 at 15:11
  • [`itertools.zip_longest`](https://docs.python.org/3/library/itertools.html#itertools.zip_longest) – bgfvdu3w Oct 04 '17 at 15:11

0 Answers0