[Tutor] Convert tuple within tuple into single tuple

Emile van Sebille emilevansebille at gmail.com
Wed Jan 11 15:05:47 EST 2017


On 01/10/2017 10:31 PM, ramakrishna reddy wrote:
> Hi All,
>
> Is there any way to convert x = (1, 2, 3, (4, 5)) to x = (1, 2, 3, 4, 5) in
> python 2.7
>

Almost:

# /usr/bin/env python
Python 2.7.3 (default, Sep 22 2012, 02:37:18)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import itertools
 >>> a = list(itertools.chain((1,2,3),(4,5)))
 >>> a
[1, 2, 3, 4, 5]


Emile







More information about the Tutor mailing list