-3

I have a list like this:

['PHE', '45', 'HIS', '46', 'HIS', '46', 'HIS', '46', 'HIS', '46', 'HIS', '46']

I want it to turn into

['PHE 45', 'HIS '46', 'HIS '46'] # it goes on like that

how can I merge consecutive list elements to eachother?

Tamer
  • 25
  • 6
  • https://stackoverflow.com/questions/5850986/joining-pairs-of-elements-of-a-list-python – Mel Jun 18 '18 at 10:51

1 Answers1

1

List comprehension for instance..

out = [str(L1[i]) + " " + str(L1[i+1]) for i in range(0, len(L1)//2, 2)]
# Out[15]: ['PHE 45', 'HIS 46', 'HIS 46']
Mathieu
  • 5,410
  • 6
  • 28
  • 55