Duplicate Returns re.compile
#1
if i have repeated returns on a re.compile is there a way to ignore or only show one of the matched


i.e
Code:
def ARTIST_SONG_INDEX(url):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        match = re.compile('target="_self">(.+?)</a></td><td class="listing-col-artist"><a href=".+?" target="_self">(.+?)</a></td>').findall(link)
        for name, url in match:
            name = str(name).replace("'","'") .replace("&amp;","and") .replace("ü","u") .replace("&quot;","")
            addDir(name,url,6,'http://live-tv-stream.googlecode.com/svn/Karaoke%20Icons/Main/SUNFLY.png')


will returns lots of matched songs

but will return

Walk Away (Kelly Clarkson)
Walk Away (Kelly Clarkson)
Walk Away (Kelly Clarkson)
Walk Away (Kelly Clarkson)


and i only want one

Walk Away (Kelly Clarkson)


obviously its not always the same song could be a different one
Reply
#2
Sounds like a use for sets: http://docs.python.org/library/sets.html
Reply

Logout Mark Read Team Forum Stats Members Help
Duplicate Returns re.compile0