return urllib.urlencode(
[(k,v) for k,v in param_dict.iteritems() if v is not None])
-def unique(seq, keepstr=True):
- """
- Return the sequence (list, tuple, etc) without repeating entries
- by Paul Rubin and Jordan Callicoat.
- http://groups.google.com/group/comp.lang.python/browse_thread/thread/40c6c455f4fd5154/744a1a338afe1331?lnk=gst&rnum=7#744a1a338afe1331
-
- for example [1,2,3,1,2] -> [1,2,3]
- """
- t = type(seq)
- if t in (str, unicode):
- t = (list, ''.join)[bool(keepstr)]
- seen = []
- return t(c for c in seq if not (c in seen or seen.append(c)))
-
def get_text(node):
"""
Given a node (<node-name> in the following example),
def field_dict(db='pubmed', page=None, parsed=None):
parsed,parsed_islocal = get_parsed_einfo(db, page, parsed)
fields = []
- tags = []
+ tags = set()
field_info = {}
fieldlists = parsed.getElementsByTagName("FieldList")
assert len(fieldlists) == 1, '%s\n\n%d FieldLists!' % (
'Multiple field names %s' % str(field['Name']))
field = delist_dict(field)
fields.append(field['Name'])
- new_tags = unique(tags + new_tags)
- if tags != []:
+ new_tags = tags.union(new_tags)
+ if tags:
assert new_tags == tags, "Inconsistent tags"
tags = new_tags
field_info[field['Name']] = field
def link_dict(db='pubmed', page=None, parsed=None):
parsed,parsed_islocal = get_parsed_einfo(db, page, parsed)
links = []
- tags = []
+ tags = set()
link_info = []
linklists = parsed.getElementsByTagName("LinkList")
assert len(linklists) == 1, (
'Multiple link names %s' % str(link['Name']))
link = delist_dict(link)
links.append(link['Name'])
- new_tags = unique(tags + new_tags)
- if tags != []:
+ new_tags = tags.union(new_tags)
+ if tags:
assert new_tags == tags, "Inconsistent tags"
tags = new_tags
link_info[link['Name']] = link