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/
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:
>
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
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