python 关于文件读写
txt文本数据格式:
12 23
13 23
...
我想把每个元素放入set中,怎么老不行。。
lines=file_relationships_of_sample_twice.readlines()
while(''!=lines):
nodeSet.update([lines[0],lines[1]])
lines=file_relationships_of_sample_twice.readlines()
求教!
[解决办法]
nodeSet = set()
file_relationships_of_sample_twice = open( "1.txt" )
for line in file_relationships_of_sample_twice :
lst = line.split()
nodeSet.update( [lst[0], lst[1]] )
print nodeSet