Steven D'Aprano wrote:
>> The following relies on undocumented (I hope) behaviour:
> preferences = [10, 30, 20]
> hosts = [ "mx1.domain.com", "anotherhost.domain.com",
>>... "mx2.domain.com"]
> hosts.sort(key=lambda x, p=iter(preferences).next: p())
> preferences.sort()
> ho
On Mon, 21 Jan 2008 09:53:10 +0100, Peter Otten wrote:
> Santiago Romero wrote:
>
>> I'm trying to sort both lists so that they end like this:
>>
>> preferences = [10, 20, 30]
>> hosts = [ "mx1.domain.com", "mx2.domain.com", "anotherhost.domain.com"
>> ]
>>
>> I want to sort hosts list depen
On Mon, 21 Jan 2008 17:32:42 +0800, J. Peng wrote:
> Steven D'Aprano 写道:
>> On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote:
>>
>>> J. Peng 写道:
>>>
k = (i.split())[3]
y = (i.split())[1]
>>> btw, why can't I write the above two into one statement?
>>>
>>> (k,y) = (i.split())[3,1]
Thanks all for the answers ... I'll use a tuple as you said :)
Anyway, is interesting to know how to sort 2 lists when you dont want
to use tuples, so thanks also to Peter :)
> Then one have to split the list twice.Given the list is large,it's maybe
> not good for performance.Is it a more effe
Steven D'Aprano 写道:
> On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote:
>
>> J. Peng 写道:
>>
>>>k = (i.split())[3]
>>>y = (i.split())[1]
>> btw, why can't I write the above two into one statement?
>>
>> (k,y) = (i.split())[3,1]
>
> I don't know. What's "i"?
>
> I'm guessing "i" is a stri
On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote:
> J. Peng 写道:
>
>>k = (i.split())[3]
>>y = (i.split())[1]
>
> btw, why can't I write the above two into one statement?
>
> (k,y) = (i.split())[3,1]
I don't know. What's "i"?
I'm guessing "i" is a string (and what a horrible choice of
Santiago Romero wrote:
> I'm trying to sort both lists so that they end like this:
>
> preferences = [10, 20, 30]
> hosts = [ "mx1.domain.com", "mx2.domain.com",
> "anotherhost.domain.com" ]
>
> I want to sort hosts list depending on the numeric order of
> "preferences".
The following relies
J. Peng 写道:
>k = (i.split())[3]
>y = (i.split())[1]
btw, why can't I write the above two into one statement?
(k,y) = (i.split())[3,1]
--
http://mail.python.org/mailman/listinfo/python-list
I tried to write it below,it can work,:)
v= """preference 10 host mx1.domain.com
preference 30 host anotherhost.domain.com
preference 20 host mx2.domain.com"""
x=v.split("\n")
li =[]
for i in x:
k = (i.split())[3]
y = (i.split())[1]
li.append((y,k))
li.sort()
print li
the output is:
On 21 ene, 08:41, Santiago Romero <[EMAIL PROTECTED]> wrote:
> Hi ...
>
> I have the following DNS MX records info:
>
> domain.com
> preference 10 host mx1.domain.com
> preference 30 host anotherhost.domain.com
> preference 20 host mx2.domain.com
> And finally ... do you think there is a bette
Hi ...
I have the following DNS MX records info:
domain.com
preference 10 host mx1.domain.com
preference 30 host anotherhost.domain.com
preference 20 host mx2.domain.com
I'm storing this info in 2 lists:
preferences = [10, 30, 20]
hosts = [ "mx1.domain.com", "anotherhost.domain.com",
"mx2.d
11 matches
Mail list logo