Type of a data structure

Asked

Viewed 37 times

0

I am trying to count the amount of dictionaries exists in a list. However the condition always of false in the if.

>>> type(record['TranslationStack'][0])
<class 'Bio.Entrez.Parser.DictionaryElement'>
>>> record['TranslationStack'][0]
{'Field': 'MeSH Terms', 'Count': '506695', 'Explode': 'Y', 'Term': '"nucleotides"[MeSH Terms]'}
>>> type(record['TranslationStack'][0]) is dict
False
  • Bio.Entrez.Parser.DictionaryElement refers to an element, item of a Dict (reading the name) and not to a dict, which is a set of elements. maybe type(record['TranslationStack'][0]) is Bio.Entrez.Parser.DictionaryElement is more likely to function.

  • It didn’t work. False Returns

1 answer

0

The Dictionaryelement elements are Wrappers relative to the basic type of Python Dict, and behave in much the same way, except because they have the 'Attributes' property that captures XML attributes.

The code below should work:

str(type(record['TranslationStack'][0]))=="<class 'Bio.Entrez.Parser.DictionaryElement'>"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.