"""
maze1.txt
4 4
o . o . o . o
- - . -
o . o . o | o
. - . .
o | o . o . o
. - . -
o . o . o . o
"""
readfile = open('maze1.txt', 'r')
line = readfile.readline()
rowcount, colcount = [int(elem) for elem in line.strip().split(' ')]
rights = []
downs = []
chars = ('o', ' ', '.', '-', '|', '')
translated = ('o', ' ', '.', '-', '|', '') # if needed, could be int or method
while line:
line = readfile.readline()
if chars[0] in line:
for elem in line.strip().split(chars[0])[1:]:
rights.append(translated[chars.index(elem.strip())])
else:
for elem in line.strip().split(chars[1])[:colcount]:
downs.append(translated[chars.index(elem.strip())])
readfile.close()
for i, elem in enumerate(rights):
print elem, divmod(i, colcount)
print "##"
for i, elem in enumerate(downs):
print elem, divmod(i, colcount)
特に「グラフ」(http://en.wikipedia.org/wiki/Graph_%28data_structure%29)に解析することを意味しますか? Pythonに "graph"組み込み型がありますか? ( 'name 'グラフが定義されていません)。あなたが作成したカスタムタイプですか?特定のアイデアはありませんが、適切な表現を提案してほしいですか? –