>Chris Torek wrote:
>> >>> x = [3, 1, 4, 1, 5, 9, 2, 6]
>> >>> list(set(x))
>> This might not be the best example since the result is sorted
>> "by accident", while other list(set(...)) results are not.
In article ,
Duncan Booth wrote:
>A minor change to your example makes it out of or
TheSaint writes:
> Thomas Rachel wrote:
>
> > Which loops do you mean here?
>
> list(set) has been proved to largely win against
> list = []
> for item in set:
> list.append(item)
> or [list.append(item) for item in set]
Remember that the criterion of speed is a matter of the implementation,
Thomas Rachel wrote:
> Which loops do you mean here?
list(set) has been proved to largely win against
list = []
for item in set:
list.append(item)
or [list.append(item) for item in set]
--
goto /dev/null
--
http://mail.python.org/mailman/listinfo/python-list
Chris Torek wrote:
> >>> x = [3, 1, 4, 1, 5, 9, 2, 6]
> >>> x
> [3, 1, 4, 1, 5, 9, 2, 6]
> >>> list(set(x))
> [1, 2, 3, 4, 5, 6, 9]
> >>>
>
> Of course, this trick only works if all the list elements are
> hashable.
>
> This might not be the best example since the result
Daniel Kluev wrote:
>> Both solutions seem to be equivalent in that concerns the number of
>> needed loop runs, but this two-step operation might require one less loop
>> over list1. The set&set solution, in contrary, might require one loop
>> while transforming to a set and another one for the &
> Both solutions seem to be equivalent in that concerns the number of needed
> loop runs, but this two-step operation might require one less loop over list1.
> The set&set solution, in contrary, might require one loop while transforming
> to a set and another one for the & operation.
python -m t
Am 15.05.2011 17:56 schrieb TheSaint:
SigmundV wrote:
I think the OP wants to find the intersection of two lists.
list(set(list1)& set(list2)) is indeed one way to achieve this. [i
for i in list1 if i in list2] is another one
Exactly. I was confused on that I wasn't able to have a list in re
In article
<34fc571c-f382-405d-94b1-0a673da5f...@t16g2000vbi.googlegroups.com>,
SigmundV wrote:
> I think the OP wants to find the intersection of two lists.
> list(set(list1) & set(list2)) is indeed one way to achieve this. [i
> for i in list1 if i in list2] is another one.
Both ways work, bu
Steven D'Aprano wrote:
s = set()
s.add(42)
s.add(42)
s.add(42)
print s
> set([42])
Good to know. I'll remember it
--
goto /dev/null
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 16 May 2011 00:05:44 +0800, TheSaint wrote:
> Chris Torek wrote:
>
>> >>> x = ['three', 'one', 'four', 'one', 'five'] x
>> ['three', 'one', 'four', 'one', 'five']
>> >>> list(set(x))
>> ['four', 'five', 'three', 'one']
>
> Why one *"one"* has purged out?
> Removing double occurences in a
Chris Torek wrote:
> >>> x = ['three', 'one', 'four', 'one', 'five']
> >>> x
> ['three', 'one', 'four', 'one', 'five']
> >>> list(set(x))
> ['four', 'five', 'three', 'one']
Why one *"one"* has purged out?
Removing double occurences in a list?
--
goto /dev/null
--
http://mail.python.org/mailman/
SigmundV wrote:
> I think the OP wants to find the intersection of two lists.
> list(set(list1) & set(list2)) is indeed one way to achieve this. [i
> for i in list1 if i in list2] is another one
Exactly. I was confused on that I wasn't able to have a list in return.
The set intersection is the sm
I'm sorry I top posted. I'll remember not to top post next time.
Sigmund
--
http://mail.python.org/mailman/listinfo/python-list
I think the OP wants to find the intersection of two lists.
list(set(list1) & set(list2)) is indeed one way to achieve this. [i
for i in list1 if i in list2] is another one.
Sigmund
On May 15, 4:11 am, Chris Torek wrote:
> In article <871v00j2bh@benfinney.id.au>
> Ben Finney wrote:
>
> >As
In article <871v00j2bh@benfinney.id.au>
Ben Finney wrote:
>As pointed out: you already know how to create a set from an object;
>creating a list from an object is very similar:
>
>list(set(aa))
>
>But why are you doing that? What are you trying to achieve?
I have no idea why someone *els
TheSaint writes:
> The example was to show that after having made a set
>
> set(aa)
>
> the need to get that set converted into a list.
As pointed out: you already know how to create a set from an object;
creating a list from an object is very similar:
list(set(aa))
But why are you doing t
On Sun, May 15, 2011 at 12:14 AM, TheSaint wrote:
> newset= set(myset1) & set(myset2)
> list= [newset]
>
> << [{'bla', 'alb', 'lab'}]
>
> Probably list(set) is not like [set].
list(set) creates a list out of the set. [set] creates a list with one
element, the set itself. It's not a copy of the se
Ben Finney wrote:
> Another method to do what?
>
Sorry, some time we expect to have said it as we thought it.
The example was to show that after having made a set
set(aa)
the need to get that set converted into a list.
My knowledge drove me to use a comprehension list as a converter.
In anothe
Peter Otten wrote:
> mylist = list(myset)
> Do you notice the similarity to converting a list to a set?
>
There was something confusing me yesterday in doing that, but (for me
strangely) I got cleared out.
The point was that after a result from:
newset= set(myset1) & set(myset2)
list= [newset]
TheSaint writes:
> Hello
>
> I've stumble to find a solution to get a list from a set
>
>
>
> >>> aa= ['a','b','c','f']
Creates a new list object. Binds the name ‘aa’ to that object.
> >>> aa
> ['a', 'b', 'c', 'f']
Evaluates the object referenced by the name ‘aa’.
> >>> set(aa)
> {'a', 'c',
TheSaint wrote:
> I've stumble to find a solution to get a list from a set
>
>
>
aa= ['a','b','c','f']
aa
> ['a', 'b', 'c', 'f']
set(aa)
To clarify: this creates a new object, so aa is still a list.
> {'a', 'c', 'b', 'f'}
[k for k in aa]
> ['a', 'b', 'c', 'f']
So you are
Hello
I've stumble to find a solution to get a list from a set
>>> aa= ['a','b','c','f']
>>> aa
['a', 'b', 'c', 'f']
>>> set(aa)
{'a', 'c', 'b', 'f'}
>>> [k for k in aa]
['a', 'b', 'c', 'f']
I repute the comprehension list too expensive, is there another method?
--
goto /dev/null
--
http:/
22 matches
Mail list logo