Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- listDic = {}
- data = ["Bird eats Prawn","Bird eats Mussels","Bird eats Crab","Bird eats Limpets","Bird eats Whelk","Crab eats Mussels","Crab eats Limpets",
- "Fish eats Prawn","Limpets eats Seaweed","Lobster eats Crab",
- "Lobster eats Mussels","Lobster eats Limpets","Lobster eats Whelk","Mussels eats Phytoplankton",
- "Mussels eats Zooplankton","Prawn eats Zooplankton","Whelk eats Limpets","Whelk eats Mussels","Zooplankton eats Phytoplankton"]
- def readFile():
- v = []
- if (len(sys.argv) == 2):
- fileName = sys.argv[1]
- else:
- fileName = input("Enter the file name: ")
- inf = open(fileName, "r")
- line = inf.readline().rstrip()
- while (line != ""):
- v.append(line)
- line = inf.readline().rstrip()
- return v
- def part1(data):
- for i in range (0,len(data)):
- splitLine = data[i].split("eats")
- if splitLine[0] in listDic:
- listDic[splitLine[0]].append(splitLine[1])
- else:
- l = [splitLine[1]]
- listDic[splitLine[0]] = (l)
- for key in listDic.keys() :
- l = listDic.get(key)
- print (key,"eats",end=":")
- for z in range (0,len(l)):
- if ((len(l) -z) ==1):
- print (l[z],end="")
- else:
- print (l[z],end=",")
- print()
- def part2():
- listPredators = listDic.keys()
- for i in range (0,len(listPredators)):
- for key in (listDic.keys()):
- listPrey = listDic.get(key)
- #print("Predator: ",list(listPredators)[i])
- #print("Prey: ",listPrey)
- #print(list(listPredators))
- for m in range (0,len(listPrey)):
- z =(list(listPrey)[m].split(" "))
- print("Predators ", list(listPredators)[i])
- print(z[1])
- if (list(listPredators)[i] == z[1]):
- print("Hello")
- def main():
- part1(data)
- part2()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement