新手程序员在这里.自学Python.关于Stackoverflow的第一个问题.
我正在尝试根据用户选择的价格,评级和烹饪类型来编写推荐餐厅的计划.为实现这一目标,该计划构建了三个数据结构:[我还处于中间阶段]
# Initiating the data structures
name_rating = {}
price_name = {}
cuisine_name = {}
Run Code Online (Sandbox Code Playgroud)
数据来自restaurants.txt,格式如下:
#Rest name
#Rest Rating
#Rest Price range
#Rest Cuisine type
#
#Rest2 name
Run Code Online (Sandbox Code Playgroud)
等等
以下函数仅返回所需行的字符串
# The get_line function returns the 'line' at pos (starting at 0)
def get_line(pos):
fname = 'restaurants.txt'
fhand = open(fname)
for x, line in enumerate(fhand):
line = line.rstrip()
if not pos == x: continue
return line
# Locating the pos's of name, rate, price & cuisine type for …Run Code Online (Sandbox Code Playgroud)