[Tutor] Testing if a number occurs more than once
alan.gauld@bt.com
alan.gauld@bt.com
Wed Dec 4 12:48:02 2002
> Jeff Shannon (and a similar one--I think!--from Alan Gauld)
> -----------------------------------------------------------
> res = {}
> for item in l:
> if res.get(item, 0):
> res[item] = 1
> else:
> return 1
> return 0
I posted a more inefficient version using dictionaries
but looping twice. I actually thought of the solution above
today and was just going to post it when I saw the latest
digest...
Ah well, at least we got there even if not directly necessary
for your requirement.
Alan G