python - How to remove duplicate values from a beautiful soup result set whilst preserving order? -
i have scenario searching through values in beautiful soup result set , treating them differently depending on contents, eg:
for in bs_result_set: if 'this unique string' in i.text: print 'aaaa' else: print 'bbbb'
however have realised unique condition occurs twice in result set not need second replicate value , therefore want remove result set in first place.
i have tried approaches removing duplicate values in list
(whilst preserving order) these not seem work on object beautiful soup result set. eg used logic this post try:
from collections import ordereddict ordereddict.fromkeys(bs_result_set).keys()
but didn't seem remove duplicate values.
so question how remove duplicate values beautiful soup result set whilst preserving order?
what about:
h = {} in bs_result_set: if not in h: if 'this unique string' in i.text: print 'aaaa' else: print 'bbbb' h[i] = 1
if key not i found i (computed, field, etc.), can do
h = {} in bs_result_set: key = <some formula involving i> if key not in h: if 'this unique string' in i.text: print 'aaaa' else: print 'bbbb' h[key] = 1
Comments
Post a Comment