-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 05/03/2011 06:20 PM, Spyros Charonis wrote: > [cat, dog, cat, cat, cat, dog, dog, tree, tree, tree, bird, bird, woods, > woods] > > I am wondering how to truncate this list so that I only print out the unique > elements, i.e. the same list but with one occurrence per element: > > [cat, dog, tree, bird, woods] > > Any help much appreciated!
The set type enforces uniqueness: http://docs.python.org/library/stdtypes.html#set You would use list(set(l)) to get the list from l where everything is unique. - -- Corey Richardson -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJNwITbAAoJEAFAbo/KNFvp9FYH/RMM0lqzBCoC5L3W4xIk6jNF gU1vs3phP/EaD/l2kil/FjRrO6nNuV91415GeSfVFKo3FXZsq0LnEaOz1b4sZCdk vmdFdONBugMixuuS8Iid3zB1hNmporc5kU2ze423MvxaDmPR0MGYYsZQ3LzFZDKK eVFTQcdvP4Tw3o21jXBcoaVHbW+GFgmxzFzsp90CgU7Dgt9o0i4YEn2IYOMETNdC 6o/EgWL7oPiWnq0os6pzo9PbhbJ9VU38ICCW/KQkk1xqrXUtXU+RHZqktWSp8kEv AQ7FqlYamOc0wZin/SSasGo7TOzVX3MFkW/rr/d8ZormCXs2tabDUcBw1XBKzok= =UcP6 -----END PGP SIGNATURE----- _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
