86,261 questions
-2
votes
1
answer
107
views
create dictionary from json [duplicate]
I have some json that looks like this:
"lines":
{
"0010": {
"ProvCountyCode": "047",
"ProvNo": "770887",
"...
5
votes
1
answer
149
views
UserDict.popitem is not LIFO
Consider the following snippet:
from collections import UserDict
class D(dict): ...
d = D(foo="bar", baz=42)
print(d.popitem()) # ('baz', 42)
class UD(UserDict): ...
ud = UD(foo="...
-4
votes
0
answers
38
views
Sorting a flat list to hierarchial nested dict when ONLY when parent is known [duplicate]
This post is followup to Nested dict with parent/child relation,, which was closed due to duplication. However, after 3 days....I will give it a try again.
To problem is following. I am trying to sort ...
Advice
2
votes
5
replies
82
views
Why do I get a TypeError when indexing a dictionary .items() result?
I am working with a dictionary in Python and trying to use the .items() function to get the key-value pairs. I saved the result in a variable l, but when I try to access the first element using l[0], ...
1
vote
1
answer
61
views
How to write a JSON string into an in-memory table in DolphinDB?
I am trying to fetch JSON data from an HTTP API and convert it into an in‑memory table in DolphinDB. The JSON response is an array of objects, and I want to store it as a table where each object ...
Advice
0
votes
4
replies
112
views
Dictionary and list handling
i would like to ask for some kind of projects in python that will help me get better at handling dict and lists i'm still not feeling very comfortable with these. If anybody knows a site for training ...
0
votes
0
answers
124
views
List inside dictionary repeating the same element indefinitely
Note: Someone in the first iteration of this question said that CheckForMagicPoint() is being called every frame, but it is not, as checkingForMagicPoints is only set to true when someone is using the ...
1
vote
1
answer
60
views
Split 2-dimensional list into a list of dictionaries with ansible
How do you turn a list of lists (2-dimensional) into a list of dicts in Ansible? I don't see how I can map it.
Take this list:
parent_list:
- - "value1-1"
- "value1-2"
- - &...
2
votes
2
answers
88
views
Using Python to group returned data from multiple table joins in MySQL
My database includes treatments (treatment_id) that are given to patients at different times during the day (due_time). I would like to display this in a GUI where each treatment has its own row and ...
1
vote
3
answers
71
views
Ansible split based on a list of strings and with the input being a list
I'm tying find good a way to split multiple FQDN domain names from a list of domains in ansible. I need to split the domain name and the unqualified name into a dictionary.
input_fqdns:
- 'host1....
-4
votes
1
answer
94
views
To what json object a Java List<String> and Map<String, String> corresponds with Jackson?
To what json object will the following java objects get converted / serialized when using jackson mapper?
List<String> textList = new ArrayList<>;
textList.add("one");
textList....
Best practices
3
votes
10
replies
239
views
How do I create a dictionary of dictionaries in Python?
I have two Python dictionaries, d1 and d2. Let them be:
d1 = {'a': 1, 'b': 2}
d2 = {'a': 3, 'b': 4}
Those dicts would be united as a new one, say new_dict:
new_dict = {1: {'a': 1, 'b': 2}, 2: {'a': 3,...
-3
votes
3
answers
120
views
How to create a member function for map?
I have created a map like this:
map<string, map<string, map<int, vector<int>>>> example;
I can insert a value to this map like this:
example["Stack"]["OverFlow&...
-1
votes
1
answer
83
views
Why does dict.update() overwrite nested dictionaries instead of merging them? [duplicate]
I’m working on merging configuration dictionaries while building a small script. I expected dict.update() to merge nested dictionaries, but it seems to completely overwrite them instead.
base = {
&...
6
votes
2
answers
170
views
What is the difference between 'Map.entry(k, v)' and 'AbstractMap.SimpleImmutableEntry::new'?
What is the difference between Map::entry and AbstractMap.SimpleImmutableEntry::new?
I tried to do research, and I really couldn't find much. It seems like Map::entry is a factory method, while ...
-1
votes
1
answer
102
views
Improving lookup time on Python dictionaries with string keys
I'm working on a project that involves generating random data according to a wide variety of specific distributions. The number of sample points to generate can go up to hundreds of thousands, ...
Best practices
0
votes
2
replies
53
views
Most practical data structure for successive levels of filtering
I'm writing a program to find substitution ciphers of a test_phrase that themselves are valid English phrases.
Example: test_phrase = 'x marks the spot' → ['a whole sky ends', 'I stage our echo', ...]
...
0
votes
1
answer
35
views
Nested Dictionary Access in Custom State Functions Causes Type Error
I'm trying to create a custom state function that needs to access nested dictionaries (dictionaries within dictionaries), but I'm encountering type errors when creating the streaming engine.
My code ...
0
votes
0
answers
29
views
How to hide or disable the search bar in the MarineTraffic iframe embed?
I am embedding the MarineTraffic map using the official <iframe> embed.
The embedded map displays a search bar, but the search does not work and always returns “Nothing to sea here”, which ...
2
votes
0
answers
51
views
why bounds in fitbounds of leaflet are not valid?
I have this map:
<l-map
ref="mapRef"
:use-global-leaflet="false"
>
and wanted to fit the map based on bounds which calculated in this way:
bounds.extend([lat, lng]);
...
Advice
1
vote
6
replies
115
views
How do I get specific values from specific keys in a dictionary?
I have made a dictionary and a list of dictionaries, but I am not sure how to get specific data from the different forms. I tried using '.startswith('7'), but it always gives me an error. I want to ...
2
votes
1
answer
116
views
Using csv how to write into file, list of dictionaries that sometimes have list inside them? [closed]
I need to create list from CSV file (it data is movies information like title, director, and actors. Directors and actors are list while other data is just string) it look like this:
with open('filmy....
-3
votes
1
answer
165
views
How do I consolidate an object of arrays of timestamped values into single array of objects? [duplicate]
I need to aggregate all the timestamped values into their sums. (Please note data may be missing for a specific log at specific timestamp.)
I have this:
const logs = {
log_1: [
{ x: "...
-3
votes
1
answer
118
views
Can't directly update a dict deepcopy [closed]
I can update a deepcopy of a dictionary in two steps. But when I try to make it a single step it returns None.
from copy import deepcopy
d0 = {'a': 1}
d1 = deepcopy(d0)
d1.update([('b', 2)])
print(d0,...
Advice
0
votes
8
replies
200
views
Finding the max values for list values for each key in a dictionary without using max()
Let's say I have a dictionary such as:
dict = { "Mars": [4, 3, 4, 7, 10], "Jupiter": [6, 6, 7, 9, 11], "Saturn": [4, 5, 12, 22, 1]}
I would like to iterate through each ...
0
votes
1
answer
155
views
Trying to create a Map in C++
I am trying to create a map of stringstreams in C++
std::map<int, std::stringstream> myMap;
std::stringstream ss;
myMap.insert(std::pair<int, std::stringstream>(1, ss));
This fails to ...
1
vote
3
answers
236
views
How to get and update multiple values with multiple keys in a dictionary with vb.net [duplicate]
I have a populated dictionary Test with two keys in TestKeys and five values in TestValues all created via structure objects:
Structure TestKeys
Public Key1 As String
Public Key2 ...
Advice
2
votes
6
replies
113
views
How to model a deep inheritance in F# and allow all items to be added to an inventory
Referring to the attached diagram for an example hierarchy of materials, how can I represent this in F#? Once represented I need to be able to add ANY/ALL of the materials in level 4 (L4) of the ...
4
votes
3
answers
232
views
How to sort a dictionary of word counts by value while preserving the original key order? [duplicate]
I am trying to count word frequencies in a text and then sort them in descending order of frequency. So if two words have the same frequency, they should remain in the same order they first appeared ...
-4
votes
1
answer
214
views
How to create a dictionary where the keys are the alphabet (A-Z), and values are a letter from a string in Python?
I have to create a dictionary, where the keys are letters of the alphabet, and the values are the indexed letters of a given string.
Example:
Given the string "BDFHJLCPRTXVZNYEIWGAKMUSQO" ...
2
votes
1
answer
232
views
Are the iterators of `map<key, value, greater<>>` and `map<key, value, less<>>` guaranteed to be the same type?
I have 2 maps
using BidBook = std::map<float, int, std::greater<>>; // price -> qty
using AskBook = std::map<float, int, std::less<>>;
I have a struct that contain iterator ...
1
vote
3
answers
91
views
How do I make a list in dictionary
This is my simple code for noting down dreams from Python crash course practices 10.7
In this practice I tried to make a list of dreams instead of simply adding a value to key
but don't how to make a ...
0
votes
1
answer
100
views
Using std::map to look up function handlers [duplicate]
I am trying to use std::map to map numerical IDs to function handlers: All function handlers take two integers and return an integer. Handler 100 would calculate the product.
When preparing the map, ...
Advice
0
votes
9
replies
145
views
Pythonic way to obtain dictionary keys with desired property
In python 3.12 I have a dictionary of which the keys are 2-tuples of integers and of which the values are integers (as in the function f:N × N → N for which f(n, m) = n + m). What I need is those keys ...
Advice
1
vote
1
replies
36
views
Is there a way to transfer MBTiles formatted maps faster?
I need to transfer a MBTiles map tiles from a disk to another, is there a faster way then just mv? It is huge and takes time.
0
votes
1
answer
172
views
How can I update values in a nested JSON file using Python? [closed]
I have a JSON file with nested objects, and I want to update specific values inside it using Python.
The structure can vary, but it usually looks something like this:
{
"user": {
"...
-1
votes
2
answers
74
views
Nested dictionary, for yaml style markup
I couldn't figure out the way to process nested leafs/branches/parents, not sure what the actual best terminology is.
I've got the reading of the data happening correctly, far as i can tell.
Its in ...
2
votes
2
answers
165
views
Convert from iferror vlookup to VBA's dictionary array
I need help with a repetitive task that I use vlookup for huge dataset, a bunch of tables of >1 million rows from multiple columns, multiple sheets of another workbook.
ID
TA
ISRC
Result
ID1
TA1
...
2
votes
1
answer
123
views
Typescript infer real entries from object literal dictionary
I have a dictionary object, very simple:
const mydict = {
key1: "value1",
key2: "value2"
}
how do I make a type that automatically converts an object like this into entries?
...
2
votes
2
answers
200
views
terra R package: problem with plet(col=…). It seems no longer admits leaflet::colorNumeric output (map becomes flat color)
I’m trying to draw a SpatRaster on a dynamic map using terra::plet() and a standard palette. The example code used to work in older terra versions (the raster showed a proper yellow/orange gradient), ...
0
votes
1
answer
232
views
Why doesn’t this f-string with double quotes raise a SyntaxError in Python 3.13.3?
I'm currently following this Python course course from Harvard.
At the point in the video, the instructor shows that the following code should raise a SyntaxError because of the conflicting double ...
1
vote
1
answer
211
views
Implementing LRU cache using std::map and std::list in C++. Can't get required output
I am trying to write C++ code to implement a cache. The cache uses Least Recently Used policy explained by the behaviour:
If the cache has a capacity to store 5 keys like 5 3 2 1 4 then if next key=1 ...
0
votes
1
answer
138
views
entrySet vs sequencedEntrySet
I want to know the difference between entrySet and sequencedEntrySet methods in LinkedHashMap in Java 21+.
I am not sure why we have sequencedEntrySet since LinkedHashMap guarantees the insertion ...
-1
votes
1
answer
96
views
Why does `Array(3).map(x => 42)` return an empty array instead of `[42, 42, 42]` in JavaScript? [duplicate]
I was brushing up on Array for an implementation and I stumbled on this discovery, I expected the following code to give me an array filled with the number 42:
Array(3).map(x => 42)
But instead, ...
0
votes
1
answer
126
views
How to rename a dictionary key and keep the order in python? [duplicate]
I have a json file to store the data for an app. This json file has this dict in it:
{
"Survival": {
"text": "Survival",
"directory": "...
0
votes
0
answers
81
views
.NET MAUI Maps Not Loading - Android
I have a .NET MAUI solution with multiple projects sharing a common library ( General). Maps were working fine previously, but now they're not loading properly in my offline project,
Problem Details
...
0
votes
2
answers
213
views
How do I access specific keys and values from CSV files?
I have a CSV file keeping track of people's score in a game. I read it with csv.DictReader().
How do I create a dictionary with the keys being the names and the value being the scores?
CSV file ...
-4
votes
1
answer
69
views
JSON DIctionary saved to S3 using S3FileSystem saved with "/ in data
I am working on a project and trying to convert a csv into JSON Dictionary and saving that JSON data file to S3 bucket via S3FileSystem. If I save this JSON DIctionary to local machine, formate is ...
-5
votes
1
answer
184
views
Convert JavaScript objects to Java objects [closed]
I want to create an object in Java, converting code from JavaScript, but I cannot find how to do so.
It's a really simple problem in JavaScript:
MINI_KEYS = ["1", "2", "3"...
0
votes
2
answers
132
views
How to sort a dictionary with list of datetime objects as value?
I have a dictionary with lists of datetime as value:
month_a = [8,9,10]
day_a = [13,12,15]
month_b = [8,9,10]
day_b = [13,11,13]
dt_a=[]
for m,d in zip(month_a, day_a):
dt_a.append(datetime....