Re: [BangPypers] Dictionary in Python - A doubt

2011-04-04 Thread Sateesh Kumar
On Thu, Mar 24, 2011 at 5:34 PM, 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. This is a Perl feature known as autovivification. http://en.wikipedia.org/

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] 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