Search code examples
pythonlistiterable-unpacking

How to unpack a list?


When extracting data from a list this way

line[0:3], line[3][:2], line[3][2:]

I receive an array and two variables after it, as should be expected:

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

I need to manipulate the list so the end result is

('a', 'b', 'c', 'd', 'e')

How? Thank you.

P.S. Yes, I know that I can write down the first element as line[0], line[1], line[2], but I think that's a pretty awkward solution.


Solution

  • from itertools import chain
    print tuple(chain(['a', 'b', 'c'], 'd', 'e'))
    

    Output:

    ('a', 'b', 'c', 'd','e')