【发布时间】:2015-12-06 17:47:03
【问题描述】:
我有一个清单:
mylist=[(u'computer', 1592), (u'student', 1113), (u'university', 1080), (u'raspberry', 1000), (u'science', 814), (u'$5', 770), (u'pi', 688), (u'exam', 571), (u'just', 544), (u'intelligence', 495), (u'solution', 475), (u'costs', 423), (u'exam:', 411), (u'latest', 402), (u"pi's", 366), (u'be', 311), (u'can', 268), (u'what', 268), (u'way', 257), (u'students', 238)]
如何在txt 文件中逐行写入该列表?,这样:
('计算机', 1592)
('学生', 1113)
('大学', 1080)
... ... ...
我怎样才能写出这样的字典
d = {u'computer':1592 , u'student':1113,........}
【问题讨论】:
-
你读过文件 I/O ...docs.python.org/2.7/tutorial/…
-
您需要更具体的格式。元组有引号但没有
u?这些东西在编写时应该看起来像 python 数据结构吗? -
@Nicqu,写成元组是没有意义的,除非你可能会腌制数据,按照我的答案的第一部分使用 csv 模块,或者如果你要使用 dict 那么只需创建一个从数据中提取并用 json 转储。
标签: python list unicode tuples