python - 如何将 csv 数据添加到我的 Hashtable?Python
问题描述
我有一个带有插入函数的哈希表,我正在尝试使用它将我的 csv 中的数据添加到表中。
def insert(self, key, value): # does both insert and update
# get the bucket list where this item will go.
bucket = hash(key) % len(self.table)
bucket_list = self.table[bucket]
# update key if it is already in the bucket
for kv in bucket_list:
# print (key_value)
if kv[0] == key:
kv[1] = value
return True
# if not, insert the item to the end of the bucket list.
key_value = [key, value]
bucket_list.append(key_value)
return True
hashtable 和 csv_reader 是项目中的单独文件。我可以看到 csv 阅读器正在使用 print(row) 输出。我可以使用插入函数调用 csv 文件中的哈希表类吗?我试图尝试 h.insert(key, value) 但是当我打印结果时它总是对我输入的任何键都说 none 尽管我可以看到数据被正确读取。希望我问的正确。感谢您的帮助!
with open('WGUPS.csv') as file:
package_data = csv.reader(file, delimiter=',')
for row in package_data:
print(row)
解决方案
推荐阅读
- ansible - 如何在Jinja2 ansible中获得两个定义变量的总和
- excel - 如何仅在给定值的Excel中求和
- reactjs - 如何在将活动链接设置为另一个链接时折叠 metismenu react js 中的菜单?
- centos7 - 如何解决 cron 计划问题?
- java - 在 RabbitMQ 中的给定日期后退订特定队列
- java - 使用正则表达式从给定的字符串值中提取子字符串
- reactjs - 错误:java.io.IOException:UT000036:连接终止解析多部分数据
- java - Maven 创建单个可执行 jar 文件
- angular - JAVA SPRING 休息应用程序在正文中收到 null
- python - 如何克服 Python 中的 TypeError