Joining pairs of elements of a list

后端 未结 6 2041
独厮守ぢ
独厮守ぢ 2020-11-27 11:32

I know that a list can be joined to make one long string as in:

x = [\'a\', \'b\', \'c\', \'d\']
print \'\'.join(x)

Obviously this would ou

6条回答
  •  情话喂你
    2020-11-27 12:12

    >>> lst =  ['abcd', 'e', 'fg', 'hijklmn', 'opq', 'r'] 
    >>> print [lst[2*i]+lst[2*i+1] for i in range(len(lst)/2)]
    ['abcde', 'fghijklmn', 'opqr']
    

提交回复
热议问题