[英]Combining two lists to form a dictionary
I have extracted the data I need from two columns of an excel sheet as two lists. 我从excel工作表的两列中提取了我需要的数据作为两个列表。 When I try to combine these two lists into a dictionary, the final output has only 300 entries whereas my excel sheet has about 1200 entries.
当我尝试将这两个列表合并成一个字典时,最终输出只有300个条目,而我的Excel工作表却只有1200个条目。 Why aren't all the entries being stored in the dictionary?
为什么不是所有条目都存储在词典中?
Here's my code: 这是我的代码:
import xlrd
xl_workbook = xlrd.open_workbook("my_doc.xls")
sheet1 = xl_workbook.sheet_by_index(0)
list1 = sheet1.col_values(2)
list2 = sheet1.col_values(3)
data = dict(zip(list1, list2))
I tried printing lengths of list1, list2, and data to cross-check. 我尝试打印list1,list2和要进行交叉检查的数据的长度。
Dictionaries can only contain unique keys. 字典只能包含唯一键。 Check the length of
set(list1)
to see how many unique keys you have. 检查
set(list1)
的长度,以查看您有多少个唯一键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.