Re: [BangPypers] Dictionary in Python - A doubt

2011-03-24 Thread Baishampayan Ghose
On Thu, Mar 24, 2011 at 5:34 PM, Jins Thomas wrote: > My problem was to find the occurance of each word in a file > > f = open('hello.txt', 'r') > count = {} > for line in f: >    words = line.split() >    for i in words : >        if i in count: >            count[i] += 1 >        else: >        

Re: [BangPypers] How to handle files efficiently in python

2011-03-24 Thread Senthil Kumaran
Vishal wrote: > size of the actual data. You should use something like this: > http://code.activestate.com/recipes/546530/ . I saved this recipe by the > name of PyObjSize which I have used below. > > >>> import PyObjSize > >>> PyObjSize.asizeof(l) > 3145848 > >>> l[0] = None > >>> PyObjSize.asize

Re: [BangPypers] Dictionary in Python - A doubt

2011-03-24 Thread Senthil Kumaran
On Thu, Mar 24, 2011 at 05:34:58PM +0530, Jins Thomas wrote: > > I was just comparing hash in Perl. In Perl 'if i in count: else:' statement > is not required i could simply uses count{i} +=1 even if it exists or not > exists. I was thinking why Python has put this restriction. Or is it > somethi

[BangPypers] Dictionary in Python - A doubt

2011-03-24 Thread Jins Thomas
Hi all, This is a very basic doubt. I was experimenting concept of dictionary in python3 My problem was to find the occurance of each word in a file f = open('hello.txt', 'r') count = {} for line in f: words = line.split() for i in words : if i in count: count[i] += 1

Re: [BangPypers] How to handle files efficiently in python

2011-03-24 Thread Vishal
On Thu, Mar 24, 2011 at 12:07 PM, Senthil Kumaran wrote: > On Thu, Mar 24, 2011 at 11:06:14AM +0530, Vishal wrote: > > setting l[0] to None, un-references the earlier string data associated > with > > that name, which is then (force) collected by the collect() call. > > Can you please elaborate th