86,290 questions
-2
votes
1
answer
171
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" ...
1
vote
3
answers
84
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 ...
Advice
0
votes
9
replies
137
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 ...
1
vote
1
answer
150
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": {
"...
2
votes
2
answers
153
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
2
answers
173
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), ...
1
vote
1
answer
197
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 ...
-1
votes
1
answer
87
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
0
answers
50
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
...
-4
votes
1
answer
61
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 ...
0
votes
2
answers
128
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....
0
votes
1
answer
104
views
Recursive function to create and populate dynamic-depth nested dictionary [closed]
I am attempting to build and populate a data structure consisting of multiple, but variable count, nested dictionaries in C#. I am currently using a recursive function to do so.
The data stored in the ...
14
votes
3
answers
1k
views
Efficient extraction of first/only key in a dictionary
Assumption is that we have a dictionary containing exactly one key/value pair. Objective is to extract the only key.
I can think of four ways to do this (there may be more).
import timeit
def func1(d):...
0
votes
2
answers
159
views
QML + OSM: Loading Offline Tiles from Local Drive
I am struggling to get Qt/QML to use downloaded tiles from local drive. The map is always generated with online tiles and not my local files.
I looked at many other posts but none of them worked for ...
0
votes
2
answers
80
views
Labeling a column's values by its criteria based on 2 different columns
Hoping that everyone is having a good one.
(This is a continuation of another question I asked which can be found here: Does Excel VBA's "Scripting.Dictionary" work in languages other ...
-1
votes
1
answer
42
views
ggplot: second geom_sf layer covers over the first one even with fill=NA [duplicate]
So zip_geo is a tigris object that has a variable at the zip code level I'd like to plot. I do it this way:
wind_map <- ggplot()+
geom_sf(data=shift_geometry(zip_geo), aes(fill=wind_group), ...
1
vote
1
answer
92
views
Pydantic does not validate dict values when assigning an unexpected type to dict values
I have the question same with link
Pydantic does not validate the key/values of dict fields
from typing import Dict
from pydantic import BaseModel
class TableModel(BaseModel):
table: Dict[str, ...
1
vote
0
answers
47
views
R tigris: Areas not in a ZCTA [duplicate]
I'm trying to create a map of the US at the zip code level to show the value of a particular variable. Used this code to create the source:
zcta_geo <- tigris::zctas(class = "sf", year=...
4
votes
3
answers
128
views
Efficient way creating a dict of dict from a pandas dataframe
I have a pandas dataframe of the following structure:
d = {'I': ['A', 'B', 'C', 'D'], 'X': [ 1, 0, 3, 1], 'Y': [0, 1, 2, 1], 'Z': [1, 0, 0, 0], 'W': [3, 2, 0, 0]}
df = pd.DataFrame(data=d, columns=['I'...
2
votes
1
answer
282
views
Dataframe behavior: Pandas 1.1.5 vs 2.3.0
I recently had to update the virtual environment for one of my libraries from Python 3.7 to 3.10, which also involved updating Pandas from 1.1.5 to 2.3.0.
In the previous virtual environment, this ...
2
votes
2
answers
85
views
Why is my code not appending into my dictionary a value under a key despite complying with the loop parameters? [closed]
I'm sorting grades by number ranges and adding them to my dictionary keys. For some reason my code is ignoring value 68 altogether.
My code:
import numpy as np
exam_results = np.array(
[
...
1
vote
1
answer
100
views
Numpy __array__ not working when return array with single item
Because plain dict is not adequate for inheritance, I design the following MyDict with UserDict in python standard libraries:
import numpy as np
from collections import UserDict
class MyUserDict(...
2
votes
1
answer
55
views
Is there an equivalent of Python's argsort function in DolphinDB?
I'm trying to implement the following functionality in DolphinDB:
Create a dictionary with city names as keys and population counts as values
Find cities with population over 10 million
Sort cities by ...
0
votes
2
answers
44
views
What is a more efficient way to add a letter to a dictionary item in gdscript
I was trying to figure out how to add an "s" to items that didn't end in "s" in a dictionary before printing the item to the console. I figured out a way to do it, but it seems ...
1
vote
0
answers
41
views
Test for multiple variables in locals().keys() fails [duplicate]
I am testing the existence of local variables LatLim and LongLim at the Spyder console:
>>> LatLim = (36.033333,36.2333)
>>> LongLim = (-5.5333,-5.25)
>>> locals().keys()
...