Re: listerator clonage

2005-02-12 Thread Raymond Hettinger
[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: > #

Re: listerator clonage

2005-02-12 Thread Alan McIntyre
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

Re: listerator clonage

2005-02-12 Thread M.E.Farmer
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

Re: listerator clonage

2005-02-12 Thread Michael Spencer
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

listerator clonage

2005-02-12 Thread Cyril BAZIN
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