Seite 1 von 1
Abfragen kürzen
Verfasst: Freitag 1. Februar 2008, 19:04
von sorgenlos
Kann man so eine Abfrage verkürzen?
Code: Alles auswählen
if keingabe == (0,0) or keingabe == (0,1) or keingabe == (0,2) or keingabe == (0,3) or keingabe == (0,4) or keingabe == (1,0) or keingabe == (1,1) or keingabe == (1,2) or keingabe == (1,3) or keingabe == (1,4) or keingabe == (2,0) or keingabe == (2,1) or keingabe == (2,2) or keingabe == (2,3) or keingabe == (2,4) or keingabe == (3,0) or keingabe == (3,1) or keingabe == (3,2) or keingabe == (3,3) or keingabe == (3,4) or keingabe == (4,0) or keingabe == (4,1) or keingabe == (4,2) or keingabe == (4,3) or keingabe == (4,4):
l1.append(Eingabe)
♠
Verfasst: Freitag 1. Februar 2008, 19:16
von BlackJack
Ja. (Wenn ich jetzt nichts übersehen habe)
Code: Alles auswählen
if 0 <= keingabe[0] <= 4 and 0 <= keingabe[1] <= 4:
ll.append(eingabe)
# oder
if all(0 <= n <= 4 for n in keingabe):
ll.append(eingabe)
Verfasst: Freitag 1. Februar 2008, 19:32
von sorgenlos
vielen danke
die erste methode hat auf anhieb funktioniert!!!
Verfasst: Dienstag 5. Februar 2008, 23:37
von sorgenlos
wie kann ich bspw. solche if-abfragen (schematisch betrachtet) kürzen?
Code: Alles auswählen
if (x-10, y+20) in sb and (x-10, y+20) not in list:
new = solve(sb[:], (x-10, y+20))
jump((x-10, y+20), new)
list.append(a_p)
if (x-10, y-20) in sb and (x-10, y-20) not in list:
new = solve(sb[:], (x-10, y-20))
jump((x-10, y-20), new)
list.append(a_p)
if (x-20, y+10) in sb and (x-20, y+10) not in list:
new = solve(sb[:], (x-20, y+10))
jump((x-20, y+10), new)
list.append(a_p)
if (x-20, y-10) in sb and (x-20, y-10) not in list:
new = solve(sb[:], (x-20, y-10))
jump((x-20, y-10), new)
list.append(a_p)
if (x+10, y-20) in sb and (x+10, y-20) not in list:
new = solve(sb[:], (x+10, y-20))
jump((x+10, y-20), new)
list.append(a_p)
if (x+10, y+20) in sb and (x+10, y+20) not in list:
new = solve(sb[:], (x+10, y+20))
jump((x+10, y+20), new)
list.append(a_p)
if (x+20, y+10) in sb and (x+20, y+10) not in list:
new = solve(sb[:], (x+20, y+10))
jump((x+20, y+10), new)
list.append(a_p)
if (x+20, y-10) in sb and (x+20, y-10) not in list:
new = solve(sb[:], (x+20, y-10))
jump((x+20, y-10), new)
list.append(a_p)
Verfasst: Mittwoch 6. Februar 2008, 00:27
von EyDu
Code: Alles auswählen
eggs = (-20, -10, 10, 20)
for xoff in eggs:
for yoff in eggs:
spam = (x+xoff, y+yoff)
if spam in sb and spam not in list:
new = solve(sb[:], spam)
jump(spam, new)
list.append(a_p)
"list" als Name ist übrigens keine kluge Idee, damit verdeckst du den Builtin-Typ "list".
Edit: Ach, eine Klammer zu viel.
Edit2: "Edit" falsch geschieben