Merge some list items in a Python List

On what basis should the merging take place? Your question is rather vague. Also, I assume a, b, …, f are supposed to be strings, that is, ‘a’, ‘b’, …, ‘f’.

>>> x = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> x[3:6] = [''.join(x[3:6])]
>>> x
['a', 'b', 'c', 'def', 'g']

Check out the documentation on sequence types, specifically on mutable sequence types. And perhaps also on string methods.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)