[EMAIL PROTECTED] wrote:
> Following Ron Adam solution (and using [] instead of list() in the last
> line), this may be a possible solution of the problem, that is often
> quite fast:
>
> def psort16(s1, s2):
> try:
> d = dict(izip(s2, s1))
> except TypeError:
> _indices =
>_ is just a plain variable name in Python. It is sometimes when a variable is
>needed to receive a value that won't be used.<
Like in some other interactive systems (Mathematica, etc, but with a
different syntax) _ has a use in the interactive shell, it contains the
last unassigned result:
>>>
Simon Sun wrote:
> Magnus Lycka wrote:
>
>>Is there something here I can't see, or did you just
>>change a variable name and present that as another
>>solution?
>
> Heh, I have use python for a very short time. Base your statements, I test
> in python, found `_' is a valid variable name. So I don
Magnus Lycka wrote:
> Is there something here I can't see, or did you just
> change a variable name and present that as another
> solution?
Heh, I have use python for a very short time. Base your statements, I test
in python, found `_' is a valid variable name. So I don't know it is a just
a plain
Following Ron Adam solution (and using [] instead of list() in the last
line), this may be a possible solution of the problem, that is often
quite fast:
def psort16(s1, s2):
try:
d = dict(izip(s2, s1))
except TypeError:
_indices = range(len(s1))
_indices.sort(key=s2
Scott David Daniels wrote:
> Ron Adam wrote:
>> Ron Adam wrote:
>> This probably should be:
>>
>> def psort11(s1, s2):
>> d = dict(zip(s2,s1))
>> assert len(d) == len(s1)
>> s1[:] = list(d[v] for v in sorted(d))
>
> You could do this to avoid all of those lookups:
>
> def psort_
Ron Adam wrote:
> Ron Adam wrote:
>> Alex Martelli wrote:
>>> Ron Adam <[EMAIL PROTECTED]> wrote:
>>>...
Considering the number time I sort keys after getting them, It's the
behavior I would prefer. Maybe a more dependable dict.sortedkeys()
method would be nice. ;-)
>>>
>>> s
Dolmans Sun wrote:
> Kent Johnson wrote:
>> >>> [a for b,a in sorted(zip(B,A))]
>
> also, [a for _,a in sorted(zip(B,A))]
>
> didn't read refs, tested above python-2.2.3.
Is there something here I can't see, or did you just
change a variable name and present that as another
solution?
--
http:
Kent Johnson wrote:
> >>> [a for b,a in sorted(zip(B,A))]
also, [a for _,a in sorted(zip(B,A))]
didn't read refs, tested above python-2.2.3.
--
Sun Yi Ming
you can logout any time you like,
but you can never leave...
--
http://mail.python.org/mailman/listinfo/python-list
Ron Adam wrote:
> Alex Martelli wrote:
>> Ron Adam <[EMAIL PROTECTED]> wrote:
>>...
>>> Considering the number time I sort keys after getting them, It's the
>>> behavior I would prefer. Maybe a more dependable dict.sortedkeys()
>>> method would be nice. ;-)
>>
>> sorted(d) is guaranteed to
Delaney, Timothy (Tim) wrote:
> Ron Adam wrote:
>
>> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
>> on win32
>>
>> I was a bit surprised by them being sorted. I just happend to try
>> d.keys() in place of s2, and it sped up. I was expecting it to be a
>> bit slower.
>
Alex Martelli wrote:
> Ron Adam <[EMAIL PROTECTED]> wrote:
>...
>> Considering the number time I sort keys after getting them, It's the
>> behavior I would prefer. Maybe a more dependable dict.sortedkeys()
>> method would be nice. ;-)
>
> sorted(d) is guaranteed to do exactly the same thin
Ron Adam <[EMAIL PROTECTED]> wrote:
...
> Considering the number time I sort keys after getting them, It's the
> behavior I would prefer. Maybe a more dependable dict.sortedkeys()
> method would be nice. ;-)
sorted(d) is guaranteed to do exactly the same thing as sorted(d.keys())
AND to be
Ron Adam wrote:
> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
> on win32
>
> I was a bit surprised by them being sorted. I just happend to try
> d.keys() in place of s2, and it sped up. I was expecting it to be a
> bit slower.
Purely an implementation accident - based
[EMAIL PROTECTED] wrote:
>> It's faster on my system because d.keys() is already sorted. But that may
>> not be the case on other versions of python.<
>
> In my version it's a little slower. But what system are you using where
> keys is already sorted? IronPython maybe?
>
> Bye,
> bearophile
Alex Martelli wrote:
> Ron Adam <[EMAIL PROTECTED]> wrote:
>
>> [EMAIL PROTECTED] wrote:
>>> Your solution Steven Bethard looks very intelligent, here is a small
>>> speed test, because sorting a list according another one is a quite
>>> common operation.
>>> (Not all solutions are really the same
>It's faster on my system because d.keys() is already sorted. But that may not
>be the case on other versions of python.<
In my version it's a little slower. But what system are you using where
keys is already sorted? IronPython maybe?
Bye,
bearophile
--
http://mail.python.org/mailman/listinf
Ron Adam <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Your solution Steven Bethard looks very intelligent, here is a small
> > speed test, because sorting a list according another one is a quite
> > common operation.
> > (Not all solutions are really the same, as Alex has shown).
>
>
[EMAIL PROTECTED] wrote:
> Your solution Steven Bethard looks very intelligent, here is a small
> speed test, because sorting a list according another one is a quite
> common operation.
> (Not all solutions are really the same, as Alex has shown).
Try this one.
def psort10(s1, s2):
d = dict
Your solution Steven Bethard looks very intelligent, here is a small
speed test, because sorting a list according another one is a quite
common operation.
(Not all solutions are really the same, as Alex has shown).
from itertools import izip, imap
from operator import itemgetter
from random impor
Steven Bethard wrote:
> Here's a solution that makes use of the key= argument to sorted():
>
> >>> A = ['hello','there','this','that']
> >>> B = [3,4,2,5]
> >>> indices = range(len(A))
> >>> indices.sort(key=B.__getitem__)
> >>> [A[i] for i in indices]
> ['this', 'hello', 'there', 'that']
>
> Ba
Brian Blais wrote:
> Hello,
>
> I have two lists, one with strings (filenames, actually), and one with a
> real-number
> rank, like:
>
> A=['hello','there','this','that']
> B=[3,4,2,5]
>
> I'd like to sort list A using the values from B, so the result would be
> in this example,
>
> A=['this'
Brian Blais <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have two lists, one with strings (filenames, actually), and one with a
> real-number rank, like:
>
> A=['hello','there','this','that']
> B=[3,4,2,5]
>
> I'd like to sort list A using the values from B, so the result would be in
> this exampl
Brian Blais wrote:
> Hello,
>
> I have two lists, one with strings (filenames, actually), and one with a
> real-number
> rank, like:
>
> A=['hello','there','this','that']
> B=[3,4,2,5]
>
> I'd like to sort list A using the values from B, so the result would be
> in this example,
>
> A=['this'
Brian Blais wrote:
> Hello,
>
> I have two lists, one with strings (filenames, actually), and one with a
> real-number
> rank, like:
>
> A=['hello','there','this','that']
> B=[3,4,2,5]
>
> I'd like to sort list A using the values from B, so the result would be
> in this example,
>
> A=['this'
Hello,
I have two lists, one with strings (filenames, actually), and one with a
real-number
rank, like:
A=['hello','there','this','that']
B=[3,4,2,5]
I'd like to sort list A using the values from B, so the result would be in this
example,
A=['this','hello','there','that']
The sort method on
26 matches
Mail list logo