小编Abd*_*00s的帖子

在Python中创建多个数据结构(dicts)

新手程序员在这里.自学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)

python dictionary

5
推荐指数
1
解决办法
76
查看次数

标签 统计

dictionary ×1

python ×1