Arrays 数组与算法
我有一个关于数组的算法作业。我的家庭作业问题如下 写一个算法来确定某本书的 数组中的名称 我为这个问题写了一个算法如下Arrays 数组与算法,arrays,algorithm,Arrays,Algorithm,我有一个关于数组的算法作业。我的家庭作业问题如下 写一个算法来确定某本书的 数组中的名称 我为这个问题写了一个算法如下 Algorithm: booksOnTheList Names : books’ list Searchname : The name to search for found <- False For each book in the books’ list { If ( book = Searchname ) then found
Algorithm: booksOnTheList
Names : books’ list
Searchname : The name to search for
found <- False
For each book in the books’ list {
If ( book = Searchname ) then
found <- True
}
print found
我犯了哪些错误和不足?谢谢您的帮助:请告诉我这是否对您有帮助
import csv
with open('file_path', 'r') as file:
reader = csv.reader(file, delimiter=',')
# because of list of list we are taking inner valid list by index
total_books_name = list(reader)[0]
books_present = []
books_not_present = []
# suppose we want to filter below list of books
input_book_list =['book_1','book_2']
for book_name in input_book_list:
if book_name in total_books_name:
print("book {} already present in list".format(book_name))
books_present.append(book_name)
else:
print("book {} not present in list".format(book_name))
books_not_present.append(book_name)
print("**** books present in collection %s", str(books_present))
print("**** books not present in collection %s", str(books_not_present))
打印“已找到”如果书籍中的Searchname\u列表中的其他内容打印“未找到”,这有点混乱,因为我刚刚开始学习,但非常感谢您的帮助: