[Tutor] Flatten a list in tuples and remove doubles

शंतनू shantanoo at gmail.com
Thu Jul 19 20:06:13 CEST 2012


You may use 'set'.

e.g.

===
>>> x
[(1, 2, 3), (1, 1), (2, 2), (1, 1), (2, 2)]
>>> set(x)
set([(2, 2), (1, 1), (1, 2, 3)])
===

On 19-Jul-2012, at 11:03 PM, PyProg PyProg wrote:

> Hi all,
> 
> I would get a new list as:
> 
> [(0, '3eA', 'Dupont', 'Juliette', '11.0/10.0', '4.0/5.0', '17.5/30.0',
> '3.0/5.0', '4.5/10.0', '35.5/60.0'), (1, '3eA', 'Pop', 'Iggy',
> '12.0/10.0', '3.5/5.0', '11.5/30.0', '4.0/5.0', '5.5/10.0',
> '7.5/10.0', '40.5/60.0')]
> 
> ... from this one:
> 
> [(0, '3eA', 'Dupont', 'Juliette', 0, 11.0, 10.0), (0, '3eA', 'Dupont',
> 'Juliette', 1, 4.0, 5.0), (0, '3eA', 'Dupont', 'Juliette', 2, 17.5,
> 30.0), (0, '3eA', 'Dupont', 'Juliette', 3, 3.0, 5.0), (0, '3eA',
> 'Dupont', 'Juliette', 4, 4.5, 10.0), (0, '3eA', 'Dupont', 'Juliette',
> 5, 35.5, 60.0), (1, '3eA', 'Pop', 'Iggy', 0, 12.0, 10.0), (1, '3eA',
> 'Pop', 'Iggy', 1, 3.5, 5.0), (1, '3eA', 'Pop', 'Iggy', 2, 11.5, 30.0),
> (1, '3eA', 'Pop', 'Iggy', 3, 4.0, 5.0), (1, '3eA', 'Pop', 'Iggy', 4,
> 5.5, 10.0), (1, '3eA', 'Pop', 'Iggy', 5, 40.5, 60.0)]
> 
> How to make that ? I'm looking for but for now I can't do it.
> 
> Thanks in advance.
> 
> a+
> 
> -- 
> http://ekd.tuxfamily.org
> http://ekdm.wordpress.com
> http://glouk.legtux.org/guiescputil
> http://lcs.dunois.clg14.ac-caen.fr/~alama/blog
> http://lprod.org/wiki/doku.php/video:encodage:avchd_converter
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list