我实际上使用以下代码从集合中获取随机整数。但是这个集合很大,所以随机选择真的很慢。有没有更好的办法?
def getRandomBook():
return int(random.sample(getBookSet(),1)[0])
def getBookSet(cleaned_sales_input = "data/cleaned_sales.csv"):
with open(cleaned_sales_input, "rb") as sales_file:
sales = csv.reader(sales_file)
return {int(row[6]) for row in sales}