>>> c = collections.Counter(a=23, b=-9)
#You can add a new element and set its value like this:
>>> c['d'] = 8
>>> c
Counter({'a': 23, 'd': 8, 'b': -9})
#Increment:
>>> c['d'] += 1
>>> c
Counter({'a': 23, 'd': 9, 'b': -9}
#Note though that c['b'] = 0 does not delete:
>>> c['b'] = 0
>>> c
Counter({'a': 23, 'd': 9, 'b': 0})
#To delete use del:
>>> del c['b']
>>> c
Counter({'a': 23, 'd': 9})
Counter is a dict subclass
Usefloatto convertstringvalue tofloat. OR We can useeval()also.
Use listappend()method to append tuple to list.
Use try except to prevent code from break.
My text file is:
-34.968398,-6.487265
-34.969448,-6.488250
-34.967364,-6.492370
-34.965735,-6.582322
Code:
p = "/home/vivek/Desktop/test.txt"
result = []
with open(p, "rb") as fp:
for i in fp.readlines():
tmp = i.split(",")
try:
result.append((float(tmp[0]), float(tmp[1])))
#result.append((eval(tmp[0]), eval(tmp[1])))
except:pass
print result
Output:
$ python test.py
[(-34.968398, -6.487265), (-34.969448, -6.48825), (-34.967364, -6.49237), (-34.965735, -6.582322)]
Richardson은 이전에몬트리올 스타에 대해 원주민 권리와 토지 개발로 인한 환경 피해에대한 일련의 기사를 썼습니다.그는 Cree 친구들과 이야기하기 위해 Mistassini로 갔고, 그들의 영화는 원주민들이 자신의 이야기를 할 수있게 해줄 것이라고 맹세했고, 촬영은 1972 년부터 1973 년까지 5 개월에 걸쳐 수풀에있는 세 명의 사냥 가족과 함께 진행되었습니다.[1]