Questions tagged [dictionary]
A dictionary maps keys to values allowing efficient retrieval of values by keys. Use the [map-function] tag for mapping functions; use the [maps] tag for geography.
dictionary
86,220
questions
3
votes
2
answers
45
views
What is wrong in my solution for Leetcode's RansomNote
I am working on the Leetcode problem 383. Ransom Note:
Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.
...
0
votes
1
answer
46
views
Best way to build a multilevel dict of dicts [duplicate]
I'm adding entries into a multi-level dict like this...
d = {}
level1 = "some level1 value"
level2 = "some level2 value"
level3 = "some level3 value"
data = "some ...
1
vote
2
answers
43
views
A list of tuples from dictionary where values are lists
I need to convert a dictionary in a form {1: ['a', 'b', 'c', 'd'], 2: ['e', 'f', 'g', 'h']} to a list of tuples in a form [(1, 'a', 'b', 'c', 'd'), (2, 'e', 'f', 'g', 'h')].
When I try that:
...
-3
votes
0
answers
17
views
How can I select these houses on an interactive and dynamic map element? [closed]
I try to get the housing units per Address in the area as it's good exercise. But I don't know how I can cycle through the addresses by clicking the individual houses with a script. I can't find the ...
-1
votes
0
answers
35
views
C++ removing LAST object from map causes program to terminate [duplicate]
I'm new to C++ and I'm working with some old C++ code. Below is a basic example of the code that is failing? There are some comments in the example code explaining the error. Basically when removing ...
-3
votes
4
answers
55
views
How to create a dictionary with a key and a list of values from multiple folders and files [closed]
I have a three folders in GCS and I want to create a dictionary that has the folder name as the key and its contents as the values with without the file_type as the values. How do I do this?
For a bit ...
-3
votes
0
answers
53
views
Use string as part of a variable name in Python [duplicate]
I would like to use a string to create a variable name.
For example, let's say I have a list of strings:
caseName = ["A", "B", "C"]
I want to create different variables ...
-4
votes
1
answer
43
views
Why KeyError in python dict but Key exists? [closed]
code:
for targetMetric in targetMetricArr:
print(targetMetric)
print(valueDict[curEndPoint].keys())
try:
print(len(valueDict[curEndpoint][targetMetric]))
except:
print('...
1
vote
4
answers
45
views
How can I rename a column in a list of data frames and the name of the column depends on the position of the data frame?
I have a list of three data frames (df1, df2, and df3) each with three columns (x, y, and z). I would like to rename a column (z) for all data frames, but the new name of the column depends on the ...
-2
votes
0
answers
42
views
Better way of mapping nested arrays in javascript? [closed]
I have an object
const resp = [
{
"projectId":"26549b0e-bf31-db41-f2c0-734be4220846",
"projectName":"Project 1",
"jobs":[
{
...
0
votes
1
answer
28
views
Use of defalut dict such that the default is a dict with an empty list [duplicate]
The main object is a dictionary whose keys are strings, values a 2nd dictionary.
The 2nd dictionary has string keys, and list values.
I want to append a new value to the empty list created using ...
0
votes
0
answers
55
views
Function can't return dictionary in VBA
I'm working on an EXCEL Macro (Microsoft office 365 for entreprise - can't find the version number).
I'm struggling with a small problem, I would appreciate some help.
In my code (below), I work with ...
-1
votes
0
answers
33
views
Hover the mouse over the location to see the details. I want to click again like Google map [closed]
I have an SVG of maps, whose path value comes from the back end and prints properly.
Now when I hover my mouse cursor over a location, it pops up like a google map with the details of that location, ...
0
votes
1
answer
27
views
How to create extended dict Class requiring key/values on get()
I'm trying to build a custom class that will require keys and/or values when getting them from a dict. This is a simple version of what I have written, getRequired and is only checking for keys.
class ...
0
votes
1
answer
45
views
How to decode a JSON API (php) call and then display it as text in a ScrollView - SWIFTUI
I have been trying to decode a JSON from a PHP that I have and then displaying the results as Text. I am getting either one of two errors with everything I have tried. The first issue would be "...
-1
votes
1
answer
57
views
tensorflow.python.framework.errors_impl.FailedPreconditionError: C:\Users\Ata Onur Özdemir\PycharmProjects\Emotion_Detection\output is not a directory
This is a sample Sentimental Analysis code for hotel reviews like positive or negative. I use pandas, transformers, datasets, turkish_lm_tuner libraries. Firstly, I think Path name (C:\Users\Ata Onur ...
0
votes
0
answers
17
views
how to view FlutterMap?
I used this flutter code to view map but the error "The named parameter 'children' is required, but there's no corresponding argument. (Documentation)" in body: FlutterMap
import 'package:...
3
votes
2
answers
60
views
Collect values as dictionary in parent column using Pyspark
I have code and data like below:
df_renamed = df.withColumnRenamed("id","steps.id").withColumnRenamed("status_1","steps.status").withColumnRenamed("...
0
votes
0
answers
10
views
Plotting def function from research paper leads to errors
I am trying to plot this complex def function from a research paper that I read for a project and I keep getting that the map function is not iterable. When I run the code by itself, it's fine, but ...
2
votes
2
answers
70
views
Replace subtrings in a list of strings using dictionary in python
I have a list of substrings:
ls = ['BLAH a b c A B C D 12 34 56',
'BLAH d A B 12 45 78',
'BLAH a/b A B C 12 45 78',
'BLAH a/ b A 12 45 78',
'BLAH a b c A B C D 12 34 99']
I want to ...
0
votes
2
answers
27
views
access target value by providing key Map<>
class CurrencyExchange {
Map<String, double> exchangeRates = {
'USD': 1.0,
'EUR': 0.85,
'JPY': 110.15,
'GBP': 0.72,
'AUD': 1.39,
'CAD': 1.25,
'CHF': 0.92,
'CNY':...
-4
votes
0
answers
50
views
How to Add values to Generic type Maps [closed]
I am trying to add some values to the Generic type MAP.
Map<T, T> Generics = new HashMap<T,T>();
How to put values to Generics, This Cannot be done in STS IDE, Whatever value type i added ...
0
votes
1
answer
40
views
Reading output of tokens_compound into a dictionary
I want to use tokens_compound to examine the frequency of phrases in the documents of a corpus. I used the corpus data_corpus_inaugural for illustrative purposes and selected some ngrams to search for....
0
votes
1
answer
23
views
Use Map<String, SomeClass> in RealmSwift?
Code example:
@objcMembers
class Obj1: Object {
dynamic var obj2: Obj2?
}
@objcMembers
class Obj2: Object {
dynamic var obj3: Obj3?
}
@objcMembers
class Obj3: Object {
dynamic var val: ...
-2
votes
1
answer
32
views
Populate the dictionary [DateComponents: EventType], How to add dates to a date dictionary
I would like to get this result:
var eventDate: [DateComponents: EventType] = [
DateComponents(calendar: Calendar(identifier: .gregorian), year: 2024, month: 7, day: 04): .busy,
...
-1
votes
2
answers
91
views
Can I reference key name in dict value definition?
Is there a way to reference name of key at definition time of the value of the key? For example:
cmds = {"DO1": get_data(key), "DO2": get_data(key), ...}
If it is available each ...
-1
votes
2
answers
47
views
Is there any way to check if a KeyValuePair<string, int> contains a specific Key in a Dictionary in one line?
In my code I have a Dictionary, which at first was just <string, int>. However, I needed a way for two things with the same string to be separate elements in the Dictionary, so I made the Key ...
-2
votes
3
answers
51
views
Split "Path Variable" string in a Dictionary in c#
I want to break the string:
value1/672/value2/32/value3/21413
In a
Dictionary<string, string>
How can I do this without the use for a for loop?
0
votes
0
answers
29
views
Map values set inside of a function not availabe in a different function
My NextJS server executes a function called "loadAllUserPools" during start up. Here's what the [abbreviated] file with this function looks like:
let userPoolMap = new Map();
export async ...
0
votes
2
answers
49
views
Covariance for value in Dictionary
I'm trying to add a more derived type as value to a dictionary<..., base> but i get the following error:
Cannot convert from HandleIntegrationEvent<TR> to HandleIntegrationEvent<...
0
votes
0
answers
31
views
ValueError: dictionary update sequence element #0 has length 1; 2 is required While trying to get command line args in jinja2
I am trying to run this code :
import sys
from jinja2 import Template
vars = sys.argv
print(vars)
myTech = {
"mad 1": 'backend',
"mad 2": 'frontend'
}
temp = Template(&...
0
votes
0
answers
49
views
Markov Chain Text Generator with CSV Input and Random Seeding [closed]
The program must only run on a Linux-Based machine and can only accept libraries of the C standard.
This program aims to generate text based on a Markov chain model using input from a CSV file. The ...
1
vote
0
answers
42
views
Reviewing nested dictionaries in Python
I have a nested dictionary inside another dictionary with a key value of a date.
The value of the dictionary (inside the dictionary) is a list of 6 numbers.
How do I access the individual numbers of ...
0
votes
2
answers
45
views
Seaborn Code for Plotting Multiple Line Plots
I used read the json file (16_results.json) to read data, I want to creates multiple line plots using the Seaborn and Matplotlib libraries to visualize data for four different values (fed_acc, fed_pre,...
1
vote
1
answer
37
views
How to get a formatted line from a dictionary var?
I'm pretty new to Ansible and I'm not sure how to get it right.
To start with, I have implemented this dictionary var for an exemple. There is 2 values but it could be a greater number:
tf_ETCD:
1:
...
0
votes
0
answers
64
views
Convert string into list of dictionaries in python [duplicate]
Used this site a bunch, but this is my first post. Thanks, in advance, to anyone who might be able to offer advice!
I'm using Python3 to read an excel file. I have a bunch of cells that contain data ...
1
vote
1
answer
45
views
How to perform a similar action on multiple cells with a varying parameter
I was asked, after providing this answer, how to make the following code work in the case where you have multiple cells (ie. TARGET_CELL_ADDRESS should take multiple values) and each cell has their ...
0
votes
1
answer
50
views
Is there a way to place a dictionary value into a variable defined by the users' input()?
Can someone please help me with the following solution? I’m relatively new to programming and I don’t seem to get what I’m doing wrong.
I have found too many dictionary functions and I am really ...
0
votes
1
answer
78
views
Why does converting a nested python dictionary into a pandas dataframe result in "has no attribute 'items' error?
I have a nested dictionary stored in the variable nested_dict_variable.
The dictionary is retrieved by using SPSS valueLabels Property (Python)
type(nested_dict_variable) results in dict.
print(...
0
votes
0
answers
26
views
How does global variable gets updated here?
This question is not seeking a solution. But an explanation for the working solution.
The problem I had was to create a nested JSON where I get the hierarchy in a dot(.) separated formate.
example
...
1
vote
1
answer
36
views
Function that returns tuples composed of a Python dictionary
I'm trying to create a function that takes a list of tokenized words for a review, and a label and returns a list of tuples composed of a Python dictionary and the label associated.
You can see what I ...
0
votes
3
answers
63
views
Creating a dictionary from a subset of a list
Suppose I have python list like this:
master_list = ['a_1', 'b_4', 'd_2', 'c_3',
'a_2', 'c_1', 'd_4', 'b_3',
'd_3', 'c_2', 'a_4', 'b_1',
'c_4', 'a_3', 'b_1'...
1
vote
1
answer
62
views
Converting between two sets of constants [duplicate]
I have two enums NAME and ALIAS which are guaranteed to have the same number of constants, and I need a way to convert each constant from NAME to its corresponding one from ALIAS, and vice-versa. For ...
-1
votes
3
answers
60
views
Trying to get dict[k] from a dict in a list of dicts for k in list or string
I have a couple dictionaries with differing values for the same keys.
I have a list of these dicts and I want to return the values from only 1 of the dicts based on the matched keys inside a different ...
4
votes
1
answer
36
views
How to restructure instance segmentation predictions into a custom dictionary format in Python?
I'm performing instance segmentation using a model trained in RoboFlow, for the prediction result I'm getting:
[InstanceSegmentationInferenceResponse(visualization=None, frame_id=None, time=None, ...
1
vote
1
answer
53
views
Creating a column based on column values and dictionaries using vectorization in pandas
I have three columns in a pandas dataframe A, B, and C. I also have 3 dictionaries, dict_A, dict_B, dict_C that have all values of A, B, and C as keys in each respective dataframe. I am trying to ...
0
votes
0
answers
20
views
Value of nested dict remains unchanged in loop [duplicate]
Consider the following:
template = {"first": "John", "last": "Doe", "numbers": {"age": 30}}
people = []
for age in range(30, 41):
...
0
votes
1
answer
72
views
change value in inner map with stream
I have this kind of map Map<String, Object> , As you can see there is a inner map "token" and inside this map, there is inner map "tokeninfo":
{
"id": "...
2
votes
1
answer
33
views
Cartesian product of dict of lists in Python [duplicate]
I would like to have a Python function cartesian_product which takes a dictionary of lists as input and returns as output a list containing as elements all possible dictionary which can be formed by ...
2
votes
1
answer
112
views
Is there any benefit of using a dictionary comprehension if an equivalent dict(zip(a, b)) is possible?
Recently I have been working with dictionaries and I was to told to make dictionaries out of two lists like this:
zipped = {key: value for key, value in zip(drinks, caffeine)}
Later I forgot how to ...