Use sets in python. let's say you want to know unique characters in url.txt
f=open('url.txt')
a=''
for x in f:
x=x.split(' ')
for y in x:
a+=y
unique=set(a)-set('@!#.')
print(unique)
print('unique characters : ',len(unique))
let's say url.txt contains:
Google --! google.com --! coolest search engine
facebook --! facebook.com --! biggest social network
yahoo --! yahoo.com --! biggest web portal
the output will be:
{'a', 'G', 'm', '\n', 'n', 'c', 'b', 'e', 'g', 'f', 'i', 'h', 'k', '-', 'l', 'o', 'p', 's', 'r', 't', 'w', 'y'}
unique characters : 22
source
share