Created
November 19, 2015 20:15
-
-
Save geekdinazor/36d719f88e3ec8f7cde7 to your computer and use it in GitHub Desktop.
Hacettepe BBM103 Assigment III Part II
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
B:C D F G A M N O | |
C:E G H | |
D:F H J N O | |
F:G M | |
G:A M | |
A:K N O | |
L:N | |
H:I A M | |
I:K M N | |
J:K | |
E:A K O | |
K:N O |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mapFileParse(): | |
f = open('paths.txt', 'r') | |
for line in f: | |
map = [] | |
for l in line[2:].replace('\r\n','').replace(' ',''): | |
map.append(l) | |
paths.update({line[0]:map}) | |
f.close() | |
def ThreeSome(path): | |
dests = set() | |
for key in paths[path]: | |
dests.add(key) | |
if key in paths: | |
dests.update(ThreeSome(key)) | |
return list(dests) | |
if __name__ == '__main__': | |
paths = {} | |
results = {} | |
mapFileParse() | |
for key in paths: | |
results.update({key : ThreeSome(key)}) | |
f = open('commandsP2.txt','r') | |
for city in f.read().split(','): | |
if city in paths: | |
print city + ":" + str(results[city]) | |
else: | |
print "City '%s' has no reachable neighbour" % (city) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment