List and order
Nic
nospam at nospam.nospam
Mon May 15 18:13:30 CEST 2006
Many thanks.
Both the cases are OK.
The only problem is that from:
12
22
21
In spite of writing
12 12 22
it writes
12 21 22
Do you know how is it possible to delete also this last trouble?
Thanks a bunch,
Nic
"Peter Otten" <__peter__ at web.de> ha scritto nel messaggio
news:e49u2k$3i2$02$1 at news.t-online.com...
> Nic wrote:
>
>> I tried to insert and execute the code, but the following error happens:
>>
>> Traceback (most recent call last):
>> File "grafodna.py", line 10, in ?
>> edges.sort(key = lambda u, v: (ddeg(u), ddeg(v)))
>> TypeError: <lambda>() takes exactly 2 arguments (1 given)
>>
>> Do you know how is it possible to delete it?
>
> Note that
>
> lambda a, b: ...
>
> takes two arguments while
>
> lambda (a, b): ...
>
> takes one argument which must be a sequence (list, string, generator,...)
> of
> two items.
>
> So the above should probably be
>
> edges = list(G.edges())
> edges.sort(key=lambda (u, v): (ddeg[u], ddeg[v]))
> for u, v in edges:
> print ddeg[u], ddeg[v],
> print
>
>
> Here's how I would do it:
>
> edges = [(ddeg[u], ddeg[v]) for u, v in G.edges()]
> edges.sort()
> for a, b in edges:
> print a, b,
> print
>
> (all untested)
>
> Peter
More information about the Python-list
mailing list