Tuesday, October 27, 2009

ఇదీ అండి మన పరిస్థితి.



అంతర్జాలం లోనూ, మంత్రులూ తెలుగు తెలుగు అని చెప్తూ ఉంటారు. తల్లిదండ్రులు పాఠశాల లలో చేర్పిస్తే చిన్న పిల్లలకి మెడలో నేరస్తుల లాగా తగిలించి 'మీరు తెలుగు మాట్లాడకూడదు, ఆంగ్లమే మాట్లాడాలి అని ఎలా తగిలించారో చూడండి. చిన్న వయసు లోనే పిల్లలకి ఇలా చేస్తే ఇంక తెలుగు బాష భవిష్యత్ ఏంటో మరి.

Monday, October 26, 2009

python prog. to find the number of occurences of each word in a file.

This program find the number of occurrences of each word in a file assuming that each line contains one word only. It is a simple prog.

def x():
file = open('input.txt', "r")
file1 = open('output.txt', 'w')
lines = file.readlines()
dictionary = {}
list = []
for line in lines:
if dictionary.has_key(line.strip()):
dictionary[line.strip()] += 1
else:
dictionary[line.strip()] = 1

keys1 = dictionary.keys()
keys1.sort()

for i in range(0, len(keys1)):

key1 = keys1[i].rjust(5)
val1 = dictionary[keys1[i].strip()]
list.append([key1, val1])

list.sort(lambda x,y: cmp(y[1], x[1]))

for i in range(0, len(keys1)):
str1 = list[i][0] +" "+ str(list[i][1]) + "\n"
file1.write(str1)

file.close()
file1.close()

It uses a lot memory since we are creating list, keys list and dictionary each is size of number of words in file.

-
Purush