I am quite new in python.I want to get unique string from a file.txt
I have some data like so…
Tempranillo Rioja_%28wine%29%23Wine_regions
Gr%C3%BCner_Veltliner Czech_Republic_%28wine%29
Marsanne California_%28wine%29
Carm%C3%A9n%C3%A8re Wines_of_Chile
Carm%C3%A9n%C3%A8re Washington_%28U.S._state%29
Gr%C3%BCner_Veltliner Czech_Republic_%28wine%29
So, I have tried with the following code:
import re
import string
import urllib
for line in open('file.txt', 'r').readlines():
left, right = string.split(line)
relation = string.split(line)
dom = relation[0]
rang = relation[1]
dom = urllib.unquote(relation[0])
dom = dom.replace('_', ' ')
rang= urllib.unquote(relation[1])
rang = rang.replace('_', ' ')
How to proceed further.I need to get unique co-occurrence of (dom rang) in this format:
Tempranillo Rioja (wine) Wine regions
Marsanne California (wine)
Any kind of help will be greatly appreciated.Thanks!
I would recommend using
urllib2— and a functional style is good for string processing like this: