Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def who_eats_who(zoo):
- endlist = [zoo]
- zoo = zoo.split(",")
- eatings = {"antelope":'grass','big-fish':'little-fish', 'bug':'leaves','bear':'big-fish, bug, chicken, cow, leaves, sheep',
- 'chicken':'bug',
- 'cow':'grass',
- 'fox':'chicken, sheep',
- 'giraffe':'leaves',
- 'lion':'antelope, cow',
- 'panda':'leaves',
- 'sheep':'grass'}
- for i in zoo:
- noeat = False
- print(i)
- print(zoo)
- while noeat == False:
- if zoo.index(i) == 0:
- if zoo[1] in eatings[i]:
- s = i + " eats " + zoo[1]
- endlist.append(s)
- zoo.pop(zoo[1])
- else:
- noeat= True
- else:
- if zoo[zoo.index(i)-1] in eatings[i]:
- s = i + " eats " + zoo[zoo.index(i)-1]
- endlist.append(s)
- del zoo[zoo.index(i)-1]
- elif zoo[zoo.index(i)+1] in eatings[i]:
- s = i + " eats " + zoo[zoo.index(i)+1]
- endlist.append(s)
- del zoo[zoo.index(i)+1]
- else:
- noeat= True
- return endlist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement