Форум сайта python.su
0
Здраствуйте!
Есть ф-ция:
def search(list, field, string): result = [] for book in list: print field print dict_fields[field] print book[dict_fields[field]] print string if string.find(book[dict_fields[field]], string)>=0: result.append(book) return result

Офлайн
568
у васstring.find(s, sub[, start[, end]]) Return the lowest index in s where the substring sub is found such that sub is wholly contained in s[start:end]. Return -1 on failure. Defaults for start and end and interpretation of negative values is the same as for slices.
string.find(book[dict_fields[field]], string)
Отредактировано FishHook (Фев. 19, 2016 14:32:16)
Офлайн
0
FishHook
Return the lowest index in s where the substring sub is found such that sub is wholly contained in s.
Return -1 on failure. Defaults for start and end and interpretation of negative values is the same as for slices.
Офлайн
568
Вы метод строки вызываете, а не функцию модуля string.
Не надо использовать зарезервированные языком слова: string, list и не будет путаницы
Офлайн
568
if string.find(book[dict_fields[field]])>=0:
Офлайн
0
FishHookАаааа, понял)))
Офлайн