86,324 questions
1
vote
2
answers
41
views
Update Pandas DataFrame slice row-wise using dictionary
Question
I am trying to update the values in a pandas (version 2.2.3) dataframe by row (such that each row has the same values) using a dictionary with row indices as keys and row values as values.
In ...
-3
votes
0
answers
47
views
Python reverse dictionary key value reference relationships [closed]
If I have a following dictionary:
{"1": {"2", "3"}, "2": {"3", "4"}, "3": {"2", "4"}}
In this dictionary, the ...
1
vote
2
answers
34
views
Excel VBA Dictionary Not Filling Corectly
I need to find the number of occurrences in a column where criteria in three other columns (same row) are met. There are also a lot of duplicates I need to exclude. This is why I am using a ...
0
votes
0
answers
23
views
How to speed up large number of calls of a pulp optimization fnction
I have a pulp function that optimizes an objective function based on relationship between two arrays. In its simplest form the objective function acts on two 1D arrays x and y each of size 20. The ...
1
vote
1
answer
22
views
AttributeError: 'Pathway' object has no attribute 'hidden'
I am attempting to create a nested dictionary 'world'. Due to the planned size and complexity I am hoping to automate the creation a bit. However, when I attempt to run it, I get "AttributeError: ...
-1
votes
1
answer
50
views
Good way to store data for my programs to reference (Python)? [closed]
I am creating a game with multiple "rooms" and each "room" has numerous data values associated with it (id number, description, rooms it connects to, etc). I was originally ...
1
vote
2
answers
95
views
Why does String.GetHashCode have O(1) complexity
I want to use string as a key type in a Dictionary. Like Dictionary<string, string>.
As I understand, if I want to Add a new object, it first calculate a hashcode of the key. So the complexity ...
-1
votes
1
answer
126
views
Efficiently populating a numpy array with dictionaries from 2D input arrays [closed]
I have the following function, that creates a large number of dict entries that describe cubes:
def fill_dict_cubes(
length: np.ndarray,
width: np.ndarray,
height: np.ndarray,
) -> np....
1
vote
2
answers
77
views
How to convert Map.adjust to monadic?
In the code it works well as below
divide :: Int -> Int -> Either String Int
divide a 0 = Left "Error with 0"
divide a b = Right (a `div` b)
The code to be changed
Map.adjust (divide ...
0
votes
1
answer
42
views
Plotting multi-dimensional array values in Flutter FlCharts
I'm trying to plot the array received from an API into FlCharts but I'm not able to correctly iterate over the second level.
My array is as follows. I'm currently testing with static sample values ...
0
votes
1
answer
33
views
Plotly Choropleth Map: Colors Not Mapping Correctly from Color Dictionary
I am trying to create a choropleth map using Plotly with a custom color dictionary, where specific states should be colored red and green. However, when trying to apply these colors, the chart is ...
0
votes
2
answers
50
views
Extract an item by name from an MapType() column in a PySpark column
I have a PySpark dataframe structured like this, where the array is formatted to start with a number: 1: "item / state / zip" most, but not all of the time. Sometimes the order will be ...
0
votes
1
answer
43
views
python Get a specific value of a label inside a loop
Simple example of the problem
# import * is bad, this is just an example
from tkinter import *
root = Tk()
root.minsize(200, 200)
dict = {"1": ("banane 1", "fresh"), &...
-2
votes
1
answer
52
views
ensure unique tuple is returned from the list of tuples [closed]
In a given list below, I want to ensure that the tuple occur uniquely. The tuple I have has two elements only. Tuple containing more than two elements are out of the scope
original_list :
[("a&...
0
votes
0
answers
25
views
Using complex objects as dictionary keys in Python
So I'm working XML files and am not quite sure if what I'm doing is 'Pythonic' enough.
The XML file has tagged text and I want to get all paragraphs that contain countries and rivers. So each ...
0
votes
1
answer
44
views
How can I create a dictionary of all values of an enum in c#?
I wish to create a dictionary with an enum key by looping over all values of the enum, e.g.
public enum MyEnum
{
First,
Second,
Third
}
Dictionary<MyEnum,int> myDict = new ...
0
votes
2
answers
50
views
Rule based dictionary manipulation in python
I have the following code that creates a dict with the keys (t,d). I have the lists T for the therapists and D for the days. Currently the same value for d is assigned for each therapist t. But I want ...
-2
votes
0
answers
25
views
Using Go language in map how to check if the file name exist or not [duplicate]
I am new to Go language,
I have list of file names in the folder , now how do I check if the file name is same as what I am expected. Please suggest me how do I achieve this. I know how to read the ...
0
votes
0
answers
53
views
ObjectMapper truncates strings in Map
I'm trying to parse a JSON string into a Map using ObjectMapper. To achieve this, I used this simple code below.
ObjectMapper objectMapper = new ObjectMapper();
Map value = objectMapper.readValue((...
1
vote
1
answer
58
views
Is there a rule-of-thumb for when caching calculations is better than recalculating them? [closed]
I have an application in which I calculate some thermodynamic properties at various pressures and temperatures. The nature of each calculation means that sometimes the properties are calculated at ...
-1
votes
1
answer
60
views
How do we know that the type of an object is Dictionary (of anything,anything)
I tried this code. ChatGPT suggested that.
Function IsDictionary(value As Object) As Boolean
' Get the type of the value
Dim valueType = value.GetType()
' Check if the type is a generic ...
0
votes
1
answer
44
views
"key not present in the dictionary" Exception despite actually existing
I have a Dictionary<FileInfo, FileStream>
Doing some tests with it. I have a single item in the dictionary. The FileInfo is X:\Thumper\levels\Basics3\sequin.master. But when I try to obtain that ...
1
vote
3
answers
62
views
Python how to set dict key as 01, 02, 03 ... when using dpath?
Let's say we want to create/maintain a dict with below key structure
{
"a": {"bb": {"01": "some value 01",
"02": "some value 02&...
0
votes
1
answer
32
views
How to get the last value in json array
How can I get the last value in a json array.
row =
{'title': 'Consolidated form', 'question_type': 'year_of_birth_question', 'tags': 'test-form', 'slug': 'test-form', 'version': 'v1.01', 'locale': '...
1
vote
2
answers
70
views
Convert JSON to set of nested Python classes
I need to process multiple messages in JSON format. Each message has its own nested structure. I would like to create a Python SDK to process these messages. My idea is to map each JSON structure into ...
1
vote
1
answer
72
views
How to create a dictionary that contains other dictionaries when we don't know their number at the beginning of the program in vba
I have the following code:
Sub Generate_report()
Dim ws As Worksheet
Dim kamagiData As Worksheet
Dim incomesData As Worksheet
Dim i As Long, lst As Long
Dim currentRow As Long
...
1
vote
1
answer
62
views
Dictionary causes weird errors swift/swiftui
I have a dictionary defined as the following:
@State var instructorNamesDictionary: [String: [String]] = [:]
Content is added to the dictionary in a .task later:
for course in courses {
var ...
0
votes
2
answers
65
views
Pycharm keeps saying there is an unmatched [ in an f-string, but it is matched
for a class I'm trying to write a python program. One of the lines tries to use an f string to report the value of a key ('cost') inside of a dictionary ('espresso') that is inside another dictionary ...
0
votes
0
answers
47
views
how to join (not nest) for loops with different indeces in python?
I have two for loops:
fig,axs = plt.subplots(11,11)
for i in range(11):
for j in range(11):
axs[i,j].plots[]
plt.tight_layout()
plt.savefig('.png')
for label in sections['ab0']:
print(label)
...
-2
votes
3
answers
81
views
How can I merge two dictionaries in Python without losing any data? [duplicate]
I'm trying to merge two dictionaries in Python, but I'm having trouble ensuring that data from both dictionaries is preserved. If a key exists in both dictionaries, I want to combine their values into ...
-2
votes
1
answer
45
views
How to perform addition to entries in Python dictionary variable?
I need to write a program that reads student grades from a text file. Each line starts with student ID, then a Section Number, then a letter grade (A, B, C, D or F).
My output needs to show the ...
1
vote
1
answer
36
views
How to create a module of constants accessible directly and through a dictionary
I want to create a module called 'constants.py' that contain all the constants specific to my system.
To offer flexibility I would like to be able to access the constants directly like this:
constants....
-2
votes
3
answers
70
views
How to ensure a unique set of dictionary values in Python by removing duplicate values?
I have a dictionary in Python where some values are repeated across different keys. I want to remove the key-value pairs with duplicate values while keeping the first occurrence. Here's an example of ...
1
vote
1
answer
59
views
Getting rid of redundant symbols after calling object from python dictionary
When I select an object from the dictionary, it shows up with Element(Name='Hydrogen', Symbol='H', Atomic_Number=1, Atomic_weight=1.008, State='Gas (Reactive nonmetal)', Melting_point=-259.1, ...
1
vote
1
answer
97
views
How to create a dictionary with initial values using collection expressions?
C# 12 introduced collection expressions and now you can write code like List<int> l = [1, 2, 3];.
When it comes to using them with dictionaries, it seems to work fine when creating an empty one ...
-4
votes
0
answers
26
views
What is sort and sorted in python [duplicate]
What is the difference between sort and sorted in Python, and how do they work with dictionaries?
"I’m trying to understand the difference between sort and sorted in Python, especially when ...
0
votes
1
answer
38
views
Google Maps Direction API Japan - No results returned for transit [closed]
I have been working on an application that uses Google Maps Directions API. I have been successful in getting Driving and Walking directions for Tokyo Japan. But once I change it to Transit, I get ...
2
votes
1
answer
45
views
java hashmap : enexpected behaviour for containsKey
Here is a code snippet :
public static void main(String[] args) {
final byte key = 0;
Map<Integer, Integer> test = new HashMap<>();
test.put(0, 10);
System.out.println(test....
-2
votes
0
answers
23
views
Is it safe to use a regular map for concurrent read/write of distinct keys? [duplicate]
Minimal Example:
I have 3 goroutines that read/write distinct keys of the same map.
Playground
package main
import (
"context"
"fmt"
"time"
)
var m map[...
1
vote
1
answer
76
views
Why am I facing difficulties with VBA in Excel when writing keys and values from a dictionary?
I want to write the keys and values of a dictionary to cells in an Excel worksheet called dash. However, when I run the code below, it only writes nome1 in column 20 without its corresponding value. ...
0
votes
0
answers
12
views
How and when to use map function on python?
Want to make a 3*3 matrix
I have tried it but it was showing error I just want to know that while making the array or matrix we use map function but i am not getting that how to use it kindly help me ...
-1
votes
0
answers
22
views
Is there a way to use Maps to control a route that doesn't go beyond country borders?
I'm working on a React project using Leaflet and OpenStreetMap to display routes between two points. However, sometimes the suggested route national borders into neighboring countries before returning ...
3
votes
1
answer
51
views
How to check if one dictionary containing list is a subset of another dictionary with list in python
Hi I have two dictionaries defined which contains lists
dict_1 = {'V1': ['2024-11-07', '2024-11-08'], 'V2': ['2024-11-07', '2024-11-08']}
dict_2 = {'V1': ['2024-11-08'], 'V2': ['2024-11-07']}
both ...
-2
votes
0
answers
70
views
Python 3.11 Two Conflicting Errors - My dictionary is a string and not a string?
I am a novice at Python, and I was wondering if someone could help me. I have searched for an answer to this and I can't find one anywhere. I am running a module where part of it is the following code:...
2
votes
1
answer
80
views
Keep duplicate dictionaries of a list of dictionaries
In my playbook, I have a list of dictionaries. I want to keep only duplicate dictionaries.
Basically it is something like:
{
"l": [
{
"a": "d",
...
0
votes
1
answer
45
views
Show message when map returns no value
i have 2 arrays categorias and noticias;
categorias is like this:
export const Categorias = [
{
id: 1,
name: "actualidade",
slug: "actualidade",
},
...
]
and ...
-1
votes
0
answers
20
views
Is there a way to combine two dictionaries into one, where the "value" become a list of elements from both dictionaries?
Let's say there's two JSON dictionaries:
dct1 = {"Alice":["c1"], "Bob":["c2","c3"]}
dct2 = {"Alice":["c3"]}
Is there an ...
0
votes
0
answers
32
views
Problems adding Fancy box to Arctic map (polar plot)
I am trying to plot a polar map on python with the zebra border line marking the longitudes. I'm using patches to generate this fancy box but it throws an error because the patch overlaps. I tried ...
0
votes
1
answer
35
views
Unit test fails for deep_update method with sets and tuples - unexpected behavior
I'm having an issue with a deep_update method that's supposed to recursively update a dictionary, including merging sets when encountered. However, my unit test is failing specifically for the case ...
0
votes
0
answers
21
views
how can i write a code that accepts an input of a number in digits and gives the output in words [duplicate]
I want to write a code that accepts an input of a number in digits and gives the output in words
example, if I input 7, the output should be seven.
I am new to python.
I tried it literally, but my ...