[Cyril BAZIN]
> I want to build a function which return values which appear two or
> more times in a list:
>
> So, I decided to write a little example which doesn't work:
> #l = [1, 7, 3, 4, 3, 2, 1]
> #i = iter(l)
> #for x in i:
> #j = iter(i)
> #for y in j:
> #if x == y:
> #
Cyril,
Here's some code that (I think) does what you want:
l = [1, 7, 3, 4, 3, 2, 1]
s, dups = set(), set()
for x in i:
if x in s:
dups.add(x)
s.add(x)
print dups
I'm sure there are more elegant ways to do it, but this seemed to be the
most straightforward way I could think of.
Ho
Cyril BAZIN wrote:
> Hello,
>
> I want to build a function which return values which appear two or
> more times in a list:
>
> So, I decided to write a little example which doesn't work:
> #l = [1, 7, 3, 4, 3, 2, 1]
> #i = iter(l)
> #for x in i:
> #j = iter(i)
> #for y in j:
> #if x
Cyril BAZIN wrote:
Hello,
I want to build a function which return values which appear two or
more times in a list:
This is very similar to removing duplicate items from a list which was the
subject of a long recent thread, full of suggested approaches.
Here's one way to do what you want:
>>> l
Hello,
I want to build a function which return values which appear two or
more times in a list:
So, I decided to write a little example which doesn't work:
#l = [1, 7, 3, 4, 3, 2, 1]
#i = iter(l)
#for x in i:
#j = iter(i)
#for y in j:
#if x == y:
#print x
In thinked