Need help...
Shagshag
shagshag13 at yahoo.fr
Wed May 8 12:41:01 EDT 2002
Thanks for your responses !!!
I think i failed to explain my needs... but your help was great...
It's ok now, i build lists (converted to tuples) from code below (feel
free to comment!!!) and use them as dictionary keys and i use a Python
list to handle "my linked list"...
(N-uples are always sorted)
-----
def build(l, n):
result = []
if n == 1:
for e in l:
result.append([e])
else:
subSet = build(l, n - 1)
for n_uples in subSet:
iLast = l.index(n_uples[-1])
print "last element %s @ %s from %s" % (n_uples[-1],
iLast, n_uples)
if iLast < len(l) - 1:
print "could add one from %s" % (l[iLast + 1:])
for e in l[iLast + 1:]:
tmp = n_uples + [e]
result.append(tmp)
print "adding %s to build %s" % (e, tmp)
return result
def allSets(l):
result = []
for i in range(2, len(l)):
print "\nbuilding set of size %s" % i
result += build(l, i)
result.append(l)
return result
----
from (a, b, c) => (a, b), (a, c), (b, c), (a, b, c)
from (a, b, c, d) => (a, b), (a, c), (a, d), (b, c), (b, d), (c, d),
(a, b, c), (a, b, d), (a, c, d), (b, c, d), (a, b, c, d)
More information about the Python-list
mailing list