0

Say I have two lists with strings:

list_a=["a", "c", "e"]

list_b=["b", "d", "f"]

I tried

combined = zip(list_a, list_b)

which forms a vertical list, but then I could only print it in the form of

[(a, b,), (c, d), (e, f)]

How could I achieve a list in the form of:

combined = ["a",  "b", "c", "d", "e", "f"]
RamenChef
  • 5,557
  • 11
  • 31
  • 43
4ku0ne
  • 1
  • 1
  • The accepted answer of the new dupe target shows the most efficient way to do this when the total number of items is under a million; for larger lists you can use `heapq.merge` as shown in sykora's answer. See the graph in J.F. Sebastian's answer. – PM 2Ring Sep 05 '16 at 07:59
  • Although my lists were not sorted, nor should they be, as they are scrambled text that needed sorting. I managed to print the vertical list using itertools. The only problem now is that it takes so much time to proccess Thank you all anyway! – 4ku0ne Sep 05 '16 at 11:57
  • If your input lists aren't (necessarily) sorted you should have mentioned that in your question, or at least not shown sample input that _is_ sorted. ;) But anyway, that's not really a big deal, since all you need to do is concatenate the input lists into a single list and sort that list, as shown in the linked question. Python's sorting algorithm, Timsort, will take advantage of sorted sub-sequences in its input, but it also performs well on totally random input. – PM 2Ring Sep 05 '16 at 12:05

0 Answers0