Skip to content
Advertisement

Tag: dictionary

Python – Find distinct domains inside a list of dictionaries

I have a list (with dictionaries inside) and I want to know how many different domains are inside it. I have something like this: The desired result would look like this: Or maybe just: Both would be OK, so whatever is easier or faster I guess. I think I could use Regex for this, but maybe there are more pythonic

Sorting by word count that store in dict python

how can you sort by word count? sorted() sort me only by the number of numbers? Thank you for your help input is print(make_dict(“test is test tests tests tests”)) output is {‘test’: 2, ‘is’: 1, ‘tests’: 3} im search output tests ,test ,is Answer You can change your code like approach_1 or use collections.Counter like approach_2. You can sorted on

How to create a dictionnary whose key:value pairs are the values of two different lists of dictionnaries?

I have 2 lists of dictionnaries that result from a pymongo extraction. A list of dicts containing id’s (string) and lemmas (strings): lemmas = [{‘id’: ‘id1’, ‘lemma’: ‘lemma1’}, {‘id’: ‘id2’, ‘lemma’: ‘lemma2’}, {‘id’: ‘id3’, ‘lemma’: ‘lemma3’}, …] A list of dicts containing id’s and multiple words per id: words = [{‘id’: ‘id1’, ‘word’: ‘word1.1’}, {‘id’: ‘id1’, ‘word’: ‘word1.2’}, {‘id’: ‘id2’,

How to print dict key value dynamically?

I’m trying to print a dict key value dynamically. EX: As we see the key ‘waninfo’ and ‘1’ are fixed and i would like to use the keys after dynamically, like this: How can i do this? Answer If there’s a constant number of keys, it might be easiest to just declare separate variables for them: If you have a

Advertisement