
Bei mir kommt natürlich immer "no" raus:
Code: Alles auswählen
d = {'a': ["x", "y", "z"], 'b': ["p", "q", "r"], 'c': []}
if "x" in d:
print "yes"
else:
print "no"
Code: Alles auswählen
d = {'a': ["x", "y", "z"], 'b': ["p", "q", "r"], 'c': []}
if "x" in d:
print "yes"
else:
print "no"
Code: Alles auswählen
Python 2.4.2 (#1, Dec 22 2005, 17:27:39)
[GCC 4.0.2 (Gentoo 4.0.2-r2, pie-8.7.8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import itertools
>>> d = {'a': ["x", "y", "z"], 'b': ["p", "q", "r"], 'c': []}
>>> for x in itertools.chain(*d.values()): print x
...
x
y
z
p
q
r
>>> "x" in itertools.chain(*d.values())
True
>>> "a" in itertools.chain(*itertools.chain(([x] for x in d.keys()),d.values()))
True
>>>
Mir war das auch neu und schon brauch ich's heute. Danke! Tolles Timing! Könntet Ihr mir auch gleich schon die Lösung für mein Problem von morgen posten? Danke!droptix hat geschrieben:die "itertools" sind mir gänzlich neu.