Skip to main content

Questions tagged [dictionary-comprehension]

A syntactic construct in Python which provides a concise way to create dictionaries.

dictionary-comprehension
0 votes
4 answers
90 views

Finding keywords in lists inside a dictionary

I have a dictionary that will have multiple dictionary / lists inside of it and I want to know how to go through each and search for keywords and add them total. Example dict1 = { "subDict1":...
Nevaeha's user avatar
  • 95
0 votes
1 answer
41 views

Compressing a list of low bit integers (2, 3, 4 bits)

I have a relatively long list of low bit integers by size 16*10^6. The sparsity level of this list is about 40%, so applying any sparse matrix does not work. The first step I tried Run-length encoding,...
daLime's user avatar
  • 47
-1 votes
1 answer
27 views

Verify if items of list are present in a another list of dictionaries [duplicate]

I have a list that looks like this: fruits = [apple,grapes,banana] I have another list called: attributes : [{'name': 'apple', 'color': 'red', 'price': '2'}, {'name': 'orange', 'color': 'orange', '...
Jimmy's user avatar
  • 21
0 votes
0 answers
29 views

Dictionary Comprehension with Pandas Data Frame, how to get all occurrences of a match? [duplicate]

name,age ben,28 laura,29 tom,28 The above is the structure of my CSV file. my_dict = {row.age: row for (index, row) in data.iterrows()} When I print(my_dict) I only see Tom and not Ben, why is one ...
Egor Ulybin's user avatar
0 votes
1 answer
20 views

Dict comprehension over multiple dicts with missing keys

I have a piece of legacy python2 code that looks like the following # dict1 and dict2 are inputs. dict2 is where the value is a 4-tuple return { key: [ NamedTuple1(val1, ...
roulette01's user avatar
  • 2,344
1 vote
2 answers
37 views

normalizing weights efficiently in python

I want to normalize weights within subgroups in a list/array. I have a working version now but it looks cumbersome and i feel there is a much more efficient way to do this. Btw, I have experience with ...
Jung Hun Kim's user avatar
0 votes
0 answers
18 views

Rego object comprehension seems incomprehensible to me; lowercase the keys

In rego, I want to convert this: d := {"a": "aye", "B": "bEe"} to: l := {"a": "aye", "b": "bEe"} where the keys are ...
theherk's user avatar
  • 7,464
0 votes
2 answers
43 views

How to add an object to a list in a dictionary using class

I have two classes: Fit class and Fit_collection which is collection of instances of Fit class. I also have two lists each element of lists need to be converted to Fit object and need to be saved to ...
user16613865's user avatar
2 votes
1 answer
103 views

Iterate over values of nested dictionary

Nested_Dict = {'candela_samples_generic': {'drc_dtcs': {'domain_name': 'TEMPLATE-DOMAIN', 'dtc_all':{ '0x930001': {'identification': {'udsDtcValue': '0x9300', 'FaultType': '0x11', '...
shekhar sabale's user avatar
1 vote
1 answer
66 views

Aggregating Inputs into a Consolidated Dictionary

Nested_Dict = {'candela_samples_generic': {'drc_dtcs': {'domain_name': 'TEMPLATE-DOMAIN', 'dtc_all':{ '0x930001': {'identification': {'udsDtcValue': '0x9300', 'FaultType': '0x11', 'description': '...
shekhar sabale's user avatar
0 votes
1 answer
33 views

Can I made use of comprehensions for comparing these lists of dictionaries?

As title. I'm trying to figure out a comprehension for this. Getting stuck adding complexity to the basic code I built so far. I feel like this would actually be easier in a comprehension, but I ...
severance26's user avatar
2 votes
1 answer
175 views

RuntimeError: await wasn't used with future - async dict comprehension in python3.8

I've finished this tutorial about async list comprehension. Now I want to try an async dict comprehension. This is the code to replicate: import asyncio async def div7_tuple(x): return x, x/7 ...
Labu's user avatar
  • 23
1 vote
2 answers
89 views

Dict comprehension taking much longer than expected

I'm profiling my simulation code, and I noticed a dict comprehension was taking quite a while. The dict comprehension looks like this: return { n : self.method(d) for n, d in zip(ns, ds) } The ...
u2j4's user avatar
  • 9
0 votes
0 answers
37 views

'ValueError: could not convert string to float: '5,742.86' [duplicate]

page=requests.get(url).text table_attribs=["Name","mc_usd_millions"] df=pd.DataFrame(columns=table_attribs) data=BeautifulSoup(page,'html.parser') tables=data.find_all('tbody') ...
mike onsongo's user avatar
1 vote
1 answer
160 views

Word file to Python dictionary

I'm trying to turn a *.docx file with questions into a python dictionary. The questions have this format: Question a. first answer b. second answer c. third answer d. fourth answer e. fifth answer ...
Simone Fildi's user avatar

15 30 50 per page
1
2 3 4 5
59