Sorting an Edge List

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Apr 29 17:51:33 EDT 2005


Anthony D'Agostino, this is my first raw version, it can fail in lots
of ways depending on your input list l (and surely there are better
ways to do it), but it's a start:

. l = [('A','Y'), ('J','A'), ('Y','J')]
. pairs = dict(l)
. result = []
. key = pairs.iterkeys().next()
. while pairs:
.     val = pairs.pop(key)
.     result.append( (key, val) )
.     key = val
. print result

Bear hugs,
Bearophie




More information about the Python-list mailing list