Я данный текстовый файл, который содержит много строк, как следующую ... много случайной информацииPython: Перебор списка
Spiaks Ресторана | 42,74 | -73,70 | 2 Archibald St + Watervliet, NY 12189 | http://www.yelp.com/biz/spiaks-restaurant-watervliet|Italian|4|5|4|3|3|4|4
Например, Spiaks Ресторан находится в положении 0, 42,74 находится в положении 1, -73,70 находится в положении 2 .... итальянский находится в положении 5 ... 4 | 5 | 4 | 3 | 3 | 4 | 4 - это еще один список ... так что в основном список в списке, а число 4 будет в позиции 6, 5 в позиции 7 .. и т. Д.
Я должен спросить пользователя и пользователя должны ответить:
What type of restaurant would you like => Italian
What is the minimum rating => 3.6
результат должен быть:
Name: Spiaks Restaurant; Rating 3.86
Name: Lo Portos; Rating 4.00
Name: Verdiles Restaurant; Rating 4.00
Found 3 restaurants.
Вот мой код:
rest_type = raw_input("What type of restaurant would you like => ")
min_rate = float(raw_input("What is the minimum rating => "))
def parse_line(text_file):
count = 0.0
a_strip = text_file.strip('\n')
b_split = a_strip.split('|')
for i in range(6, len(b_split)):
b_split[i] = int(b_split[i]) # Takes the current indices in the list and converts it to integers
count += b_split[i] # Add up all of the integers values to get the total ratings
avg_rate = count/len(b_split[6:len(b_split)]) # Takes the total ratings & divides it by the length
#The above basically calculates the average of the numbers like 4|5|4|3|3|4|4
if (rest_type == b_split[5] and avg_rate >= min_rate):
print b_split[0], avg_rate
Проблема результата .. я получаю:
None
Я знаю, что это очень, очень длинный вопрос, но если кто-то может дайте мне некоторое представление, я был бы признателен!