[Baypiggies] list question
hasan.diwan at gmail.com
Wed Apr 6 05:02:22 CEST 2011
On 6 April 2011 04:49, Vikram K <kpguy1975 at gmail.com> wrote:
> i have this list:
> x = ['cat','dog','dog']
> i wish to identify the non-unique element in this list i.e. 'dog'. how do i
> do this?
> i did this:
> >>> y = list(set(x))
> >>> y
> ['dog', 'cat']
You are on the right track here. However, I would build a list and check for
membership in it right after, e.g.:
for animal in x:
if animal not in unique: unique.append(animal(
else: print animal
for your list ['cat', 'dog', 'dog'] the above snippet gives 'dog'
Sent from my mobile device
Envoyait de mon telephone mobil
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Baypiggies