Kent Johnson wrote:
> This is a popular question. It comes up frequently on comp.lang.python
> and there are many recipes in the online cookbook.
Here is a good starting point if you want to see a variety of ways to
uniquify (?) sequences:
http://tinyurl.com/3cqnj5
Make sure you look at the ref
Andrei wrote:
>>> Alternatively, you could put the results as keys in a dictionary,
>>> then request
>>> mydict.keys() to get a list of unique outcomes.
>> I thought of that too, but couldn't think how to do it in a list
>> comprehension. It seemed like it should be possible but I
>> couldn't thin
>> Alternatively, you could put the results as keys in a dictionary,
>> then request
>> mydict.keys() to get a list of unique outcomes.
>
> I thought of that too, but couldn't think how to do it in a list
> comprehension. It seemed like it should be possible but I
> couldn't think of how - and di
Alan Gauld wrote:
> "Smith, Jeff" <[EMAIL PROTECTED]> wrote
>
>> In other words, applying somefun to the results of the iterator
>> return
>> duplicates but I want the constructed list to contain none.
>
>> l = [somefun(i) for i some-iterator if somefun(i) not in l]
>>
>> doesn't work (not that
"Andrei" <[EMAIL PROTECTED]> wrote
> Alternatively, you could put the results as keys in a dictionary,
> then request
> mydict.keys() to get a list of unique outcomes.
I thought of that too, but couldn't think how to do it in a list
comprehension. It seemed like it should be possible but I
coul
Andrei wrote:
>> "Smith, Jeff" medplus.com> wrote
>>
>>> In other words, applying somefun to the results of the iterator
>>> return
>>> duplicates but I want the constructed list to contain none.
>>> l = [somefun(i) for i some-iterator if somefun(i) not in l]
>>>
>>> doesn't work (not that I expe
On Mar 2, 2007, at 9:56 AM, Alan Gauld wrote:
> Why not use a Set?
>
> s = Set([somefun(i) for i in some-iterator])
>
> Might be slow for big lists though...
I'm curious why using a Set would be slower than doing it in a loop?
In either case, the processor has to scan through all the data
l
> "Smith, Jeff" medplus.com> wrote
>
> > In other words, applying somefun to the results of the iterator
> > return
> > duplicates but I want the constructed list to contain none.
>
> > l = [somefun(i) for i some-iterator if somefun(i) not in l]
> >
> > doesn't work (not that I expected it to).
Smith, Jeff wrote:
> I find a common thing to do is
>
> l = list()
> for i in some-iterator:
> if somefum(i) != list:
> l.append(somefun(i))
How about using the same condition you do in the if? Like:
l=[somefun(i) for i in some-iterator if not type(somefun(i)) is list]
HTH
Jordan
_
"Smith, Jeff" <[EMAIL PROTECTED]> wrote
> In other words, applying somefun to the results of the iterator
> return
> duplicates but I want the constructed list to contain none.
> l = [somefun(i) for i some-iterator if somefun(i) not in l]
>
> doesn't work (not that I expected it to).
Why not u
I find a common thing to do is
l = list()
for i in some-iterator:
if somefum(i) != list:
l.append(somefun(i))
In other words, applying somefun to the results of the iterator return
duplicates but I want the constructed list to contain none.
l = [somefun(i) for i some-iterator]
will
11 matches
Mail list logo