SunJune
03-22-2011, 05:26 AM
Hi Everyone,
I have a file as below and want to have a output in the following format (second block). So far I have been able to get the result (please see third block). My code is in last block.
As you can see I am still getting the numbers as well in my output, how can I get rid of that? I searched a lot, but couldnt able to get it.
I still have to write the code for counting the items, but need to get this working first.
Please advise..
Now
is the time
for all good-men
to come to the-
aid of -their
party. NOW IS THE TIME FOR all Good men to
come to the AID of their party. party-their now-is time-the-for all-good
men to -come aid of party a&b%c*(d)
a1b2c3d4-
a
b
b c defg
thisisaverylongWORDwithnospacesbetweenthewordsandhowwillitbehandled?
thisisaverylongWORDwithnospacesbetweenthewordsandhowwillitbehandled2?
thisisaverylongWORDwithnospacesbetweenthewordsandhowwillitbehandled3?
!"£$%^&*()
: 3
aid: 3
all: 3
b: 4
c: 3
come: 3
d: 2
defg: 1
for: 3
good: 3
is: 3
men: 3
now: 3
of: 3
party: 4
the: 5
their: 3
thisisaverylongwordwithnospacesbetweenthewordsandhowwillitbehandled: 3
time: 3
to: 5
['now']
['is', 'the', 'time']
['for', 'all', 'good', 'men']
['to', 'come', 'to', 'the']
['aid', 'of', 'their']
['party', 'now', 'is', 'the', 'time', 'for', 'all', 'good', 'men', 'to']
['come', 'to', 'the', 'aid', 'of', 'their', 'party', 'party', 'their', 'now', 'i
s', 'time', 'the', 'for', 'all', 'good']
['men', 'to', 'come', 'aid', 'of', 'party', 'a', 'b', 'c', 'd']
['a1b2c3d4']
['a']
['b']
['b', 'c', 'defg']
['thisisaverylongwordwithnospacesbetweenthewordsandhowwillitbehandled']
['thisisaverylongwordwithnospacesbetweenthewordsandhowwillitbehandled2']
['thisisaverylongwordwithnospacesbetweenthewordsandhowwillitbehandled3']
[]
[]
#!/usr/bin/python
import re
fo=open("wordList.txt","r+")
for line in fo:
line=line.lower()
#print(line,end='')
matches=re.findall(r'\w+',line)
print(matches)
I have a file as below and want to have a output in the following format (second block). So far I have been able to get the result (please see third block). My code is in last block.
As you can see I am still getting the numbers as well in my output, how can I get rid of that? I searched a lot, but couldnt able to get it.
I still have to write the code for counting the items, but need to get this working first.
Please advise..
Now
is the time
for all good-men
to come to the-
aid of -their
party. NOW IS THE TIME FOR all Good men to
come to the AID of their party. party-their now-is time-the-for all-good
men to -come aid of party a&b%c*(d)
a1b2c3d4-
a
b
b c defg
thisisaverylongWORDwithnospacesbetweenthewordsandhowwillitbehandled?
thisisaverylongWORDwithnospacesbetweenthewordsandhowwillitbehandled2?
thisisaverylongWORDwithnospacesbetweenthewordsandhowwillitbehandled3?
!"£$%^&*()
: 3
aid: 3
all: 3
b: 4
c: 3
come: 3
d: 2
defg: 1
for: 3
good: 3
is: 3
men: 3
now: 3
of: 3
party: 4
the: 5
their: 3
thisisaverylongwordwithnospacesbetweenthewordsandhowwillitbehandled: 3
time: 3
to: 5
['now']
['is', 'the', 'time']
['for', 'all', 'good', 'men']
['to', 'come', 'to', 'the']
['aid', 'of', 'their']
['party', 'now', 'is', 'the', 'time', 'for', 'all', 'good', 'men', 'to']
['come', 'to', 'the', 'aid', 'of', 'their', 'party', 'party', 'their', 'now', 'i
s', 'time', 'the', 'for', 'all', 'good']
['men', 'to', 'come', 'aid', 'of', 'party', 'a', 'b', 'c', 'd']
['a1b2c3d4']
['a']
['b']
['b', 'c', 'defg']
['thisisaverylongwordwithnospacesbetweenthewordsandhowwillitbehandled']
['thisisaverylongwordwithnospacesbetweenthewordsandhowwillitbehandled2']
['thisisaverylongwordwithnospacesbetweenthewordsandhowwillitbehandled3']
[]
[]
#!/usr/bin/python
import re
fo=open("wordList.txt","r+")
for line in fo:
line=line.lower()
#print(line,end='')
matches=re.findall(r'\w+',line)
print(matches)