Questions tagged [dictionary]
A dictionary maps keys to values allowing efficient retrieval of values by keys. USE [map-function] TAG for mapping functions; and for geography, [maps].
85,110
questions
0
votes
0
answers
10
views
create a DataFrame from a dictionary, ValueError: Per-column arrays must each be 1-dimensional
I'm trying to create a Panda dataframe from a dictionary to plot a performance curve.
It was working in 2020, but now no.
model = ExtraTreesRegressor()
feature_selector = RFECV(estimator=model, ...
-3
votes
0
answers
31
views
Need a way to remove multiple dictionary key-value pairs from a list within a dictionary within a list based on a value
I have been working for hours on this, but I am not very good at python and need assistance:
Basically I want this:
list = [
{'id': '3334a39ac46322911bb2cc9243e387ee',
'sport_key': 'baseball_mlb',
...
0
votes
2
answers
30
views
How can I arrange a dictionary using python so that the values are represented from lowest to highest order?
I have the following dictionary:
d = {'A': {'A1': 2, 'A4': 4, 'A5': 1}, 'B': {'B3': 1, 'B7': 8, 'B5': 2}}
How can I rearrange the dictionary to organize the values from lowest to highest order?
I am ...
0
votes
2
answers
33
views
Search dictionary for specific key in tuple
I have created a dictionary using tuples
stateinfo = {
('Ohio', 'Columbus', 'Scarlet Carnation'): 11747774,
('Texas', 'Austin', 'Bluebonnet'): 30500280,
('North Carolina', 'Raleigh', 'Dogwood'): ...
0
votes
2
answers
22
views
Is there a way to sort a dictionary into number order with negative numbers? [duplicate]
I am trying to sort a dictionary into an order with negative numbers. This seems like an easy task but for some reason I can't get it. I've seen a few similar solutions but they're either not exactly ...
-1
votes
0
answers
34
views
Python's max() function doesn't work on dictionaries if the keys are of type Enum [closed]
I have a dictionary whose keys are of type Enum and values are floating point numbers. If I use the max() function over such a dictionary, it results in TypeError.
Here is a sample code tested on ...
1
vote
2
answers
41
views
Python | Create a Dictionary with Values as expressions without evaluating or treating it as string
I need to create a dynamic synthetic Pandas DF in Python and am using Faker and Random functions to create the same.
To do so, I am creating a dictionary as a source to build pandas df where some ...
1
vote
0
answers
51
views
Is it more efficient to create an empty dictionary and insert values individually, or to create a dictionary as a single expression?
In Python 3, I wasn't sure which piece of code is more efficient.
Initializing an empty dictionary and adding key, value pairs into it:
my_dict = {}
my_dict['a'] = 1
my_dict['b'] = 2
my_dict['c'] = 3
...
0
votes
1
answer
19
views
How to update/add the new/existing contents of a dictionary inside a list from a list reference
I have a dynamic list of contents which varies on timely basis. Based on the contents of the dynamic list, I need to add/update the dictionary inside the another list.
list1 = ["data1", &...
-1
votes
2
answers
28
views
How to generate a flattened JSON with exact rows as one list of dict has for a CSV file from a JSON in Python?
I'm generating a CSV file from JSON.
How can I get flatter JSON with the exact rows as one list of dict has?
The data in rows will be almost the same, except for a few columns which will be variate.
...
0
votes
2
answers
19
views
How can I control the order of attributes when converting dataclasses to a dict in Python?
i want to used named data in my project but in the end i have to convert the data to a CSV file.
My approach is to use list of dataclasses in the code as data containers. In the end the list of ...
0
votes
1
answer
16
views
How to use multiple columns as maps for nested dictionary to create a new dataframe column?
I am trying to use 2 pyspark dataframe columns as an input to a nested dictionary to get the output as a new pyspark column. Also would want the solution to scale to a nested dictionary with 4-5 ...
0
votes
0
answers
7
views
Trouble making an image appear on mouseover in HTML using button and image map
I'm sorry if I will ask silly questions, but do you know, what is missing in my code, to make an image appear when the mouse passes on a button or over coords? I am trying two ways, one is by putting ...
0
votes
1
answer
56
views
Why is this class not comparing equal to a string when it should?
I have a class that essentially wraps a string so that I can make a custom editor for this class easily. I want this class to act as if it is a string when comparing to other classes. I am using this ...
0
votes
1
answer
17
views
Accessing values after enumerate when iterating through a dict
I have code that iterates through a large dataframe using df.itertuples()
I understand this is slow, and can be much faster if I convert to a dict and use df.to_dict('records)
The problem I am having ...
0
votes
1
answer
31
views
best practice to update a field in list of dictionary of list and dictionary
Assuming the input is a list of dictionary.
I need to update a specific field with new values.
There are repeated keys, values in the input so cannot distinguish the field need to be picked by its ...
-1
votes
2
answers
36
views
Need help in accessing dictionary values in list
I am trying to access the values in list of dictionary where I need to pass key and value as string
ex: I have list of dictionary -
details = [{'name': 'veeresh', 'href': 'www.google.com', 'id': '...
-1
votes
0
answers
35
views
The given key was not present in the dictionary On Antlr4 based and C# implementation
I am working on Antlr4 and C#, i wanted to implement Dictionary like feature, after implementation i tried to test but not working flagging an error The given key was not present in the dictionary.
...
2
votes
2
answers
44
views
How to filter a dictionary using another dictionary?
I have two sets of dictionaries. Let's call them A and B. I need to be able to create a third dictionary, C, which has all the keys and associated values of A, except for the pairs that are in B. This ...
0
votes
1
answer
54
views
Caching of arbitrary functions and values in Python
I am working on a cache handler class that given an arbitrary function and a set of arguments caches its result. This will be used in a load-balancing MPI scheduler written in python. Although the ...
-1
votes
3
answers
41
views
Getting all keys with highest value in a dictionary
In python dictionary, how to search the max value and return the key of the max value in a list. For instance, 3 is the max value in this dictionary.
Given:
Frequency = {9: 3, 2: 3, 6: 2, 8: 1, 1: 1}
...
0
votes
2
answers
42
views
Convert json directly into dictionary of pandas dataframes
I have json files which look like a dictionary of a list of similar dictionaries:
{"People":[{"FirstName":"Max","Surname":"Smith"},{"FirstName&...
-3
votes
2
answers
33
views
print values of each key in the dictionary with python
How to print the values of each key in the dictionary with python?
For example this dictionary:
{
'switch1':'s1-eth1,s1-eth2',
'switch2':'s2-eth1,s2-eth2'
}
My expected output:
'switch1':'s1-eth1'
'...
0
votes
0
answers
29
views
Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'Map<String, MovieList>?' in type cast
Error: Unhandled Exception: type 'List' is not a subtype of type 'Map<String, MovieList>?' in type cast
I am currently trying to read a data from a firebase realtime database, by using the ...
0
votes
2
answers
52
views
Triple-Bound Dictionary-Like Data Structure?
I'm trying to create a data structure that binds 3 elements together, and where any of the 3 elements can be used as the key.
Up till now, I've been using a bunch of functions that convert from one ...
0
votes
2
answers
25
views
Issue with dictionary values not appending in Django session
I'm encountering an issue with updating dictionary values in Django session. Initially, I was using a list to store data in the session, and it worked perfectly fine. However, when I switched to using ...
0
votes
0
answers
31
views
Why is the href data the same in every element of the areas list, but the id and name elements are correctly different?
areaDict = {
"id": "",
"name": "",
"urls": [["", ""], ["", ""]],
}
areas = []
def getCouncils():
page = ...
-1
votes
0
answers
21
views
can anyone help me how to make a collision for 2d map that keep work for all kind of pathfinding that will add later in the code?
I want to make an AI simulation of hide and seek, the problem is when i spread all the tile i can't make the collision for it so the seeker and the hider keep walking across the wall while the ...
0
votes
0
answers
28
views
Is it possible to change the internal hashing function of Python dictionaries?
I am trying to write a program which uses Locality Sensitivity Hashing and CityHash to perform a double hash on strings (Kmers) in order to find similarity between long gene sequences. I've been able ...
0
votes
2
answers
38
views
There is an error that i cannot figure out in python the error is = "[" was not closed Pylance
students = ['Hamza' : 14, 'Bob' : 15, 'Bilal' : 13]
this is my code and i am making a dictionary that has the names and ages of some students. but, an error comes "[" was not closed Pylance
...
0
votes
2
answers
45
views
Finding keys with the minimum values in each group in a dictionary with jumps (Python)
I have a dictionary where jumps happen in its keys. How can I find the key in between each group where the value is minimum?
For example, I have
myDict = {
0.98:0.001,
1.0:0.002,
...
0
votes
0
answers
22
views
Except block is not executed
I am tryng to make a function that has as parameters 2 dictionaries and uses a try block to update one of them but if I enter a wrong key nothing happens from the except.
try:
player[item['Type']] ...
0
votes
1
answer
19
views
Python3 - Kivy RecycleView's data Dictionary succefully updated, but not phisically the Widget
In a Kivy form i set 2 Recycleviews(A and B). I would add the item clicked in Recycleview A, to the RecycleView B, using a Python3 script:
from functools import partial
from kivy.app import App
from ...
1
vote
1
answer
98
views
From Python's nested dictionary to flat Pandas dataframe
I have a nested dictionary of the public information of employment history of people and I would like to construct the panel data similar to the following table.
Here is the nested dictionary.
The ...
0
votes
2
answers
53
views
Dictionary popping
I'm trying to pop they key if it is not in dictionary thisdict but I keep getting a key error
userList = [User(id='1', username='bob'), User(id='2', username='john')]
players = {}
players['1'] = 'bob'
...
2
votes
1
answer
25
views
Is it possible to combine comprehension and key-value listing in dictionary definition?
I am trying to define a dictionary wherein some key-value pairs can be specified using comprehension (because these pairs are formulaic), while others need to be specified explicitly. Due to a coding ...
1
vote
2
answers
22
views
Python: Replace values from one nested dictionary to another dictionary
I have two dictionaries CAN0 and CAN1 as follows:
CAN0 = {
"signal11" : 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
"signal12" : 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
"signal21&...
2
votes
1
answer
84
views
Reorganize nested `dict`
This question is connected to [-> here].
I would like to reorganize the following nested dict please:
a = {
(0.0, 0.0): {'a': [25, 29, nan]},
(0.0, 2.0): {'a': [25, 29, nan], 'b': [25, 35, 31.0]},...
1
vote
1
answer
23
views
Implement MultiKeyDict class in Python with alias() method for creating aliases. Existing code fails when original key is deleted. Need fix
Python OOP problem
MultiKeyDict class, which is almost identical to the dict class. Creating an instance of MultiKeyDict class should be similar to creating an instance of dict class:
multikeydict1 = ...
-1
votes
0
answers
15
views
how to change the position of compass in google_maps_flutter [duplicate]
enter image description here
I need to change the position of compass from right to anywhere in app.It always shows right in Flutter google map.Is it possible to change position??
Stack(
...
0
votes
0
answers
13
views
3D needle bars and map not rendering when using a slider - plotly/Python
the code is supposed to lay a basemap and 3d needle bars that change based on the month chosen by the slider. The only thing is that once I did a update_slider() slider code, it just started not ...
0
votes
1
answer
21
views
How can i add new key and value in a existing list
I'm trying to create a blind auction. So basically it will ask for your name and then your bid. After that, it will ask if there are any bidders, if yes it will ask you the name and the bid price. But ...
-1
votes
0
answers
17
views
Cannot select an item from a Python Dictionary [closed]
Cannot select 'count' from Python Dictionary. 'description' works fine and seems to be at the same level?
Desired which does not work:
for item in library:
print(item['title'],' - ', item['...
1
vote
2
answers
66
views
How can I iterate through a list of dictionaries and extract a subset of values in Python using loops?
Iterate through a list of dictionaries to get subset
I have a python list as follows:
data_list is equivalent to values key
in a dictionary object which is a list of items
"values": [
...
-1
votes
0
answers
29
views
Qt Quick Map isn`t updating
I currently learning QML and I am following this (tutorial). I have used this sample code from the Qt documentation as in the totorial and it works but the map is not interactive like in the ...
0
votes
1
answer
47
views
loop through nested dictionary/list in Python and save key-value pairs
I'd like to loop through this nested dict/list and return all occurrences of input key-value pairs. The length and the depth of each level may vary.
For example I'd like to have all the {'dd': 22}.
...
0
votes
2
answers
24
views
Get the last true condition of multiple True conditions that there are in a list
I have a list of dictionaries, where each dictionary is of the format.
{'id': 'XYZ_ALL_UNIQUE',
'event_type': 'TYPE OF EVENT',
'created_time': '2023-05-29T11:23:54.456170Z'
}
There are multiple ...
0
votes
1
answer
55
views
Nested-Dictionary Python
I am having an issue with nested dictionaries.
I have a dataframe in which one column ['spikes'], contains a series of nested dictionaries like so:
spikes =
1 {'20230516_1352_E_sorted': {'chan1_1':...
-1
votes
0
answers
17
views
Swift - Help needed to sort an array of dictionaries of strings [duplicate]
Good day, I am having a big big issue on my SWIFT code and my app was released yesterday, I am having an Array of Dictionaries in string mode, and i am using a Sort and numbers are getting sorted in a ...
1
vote
1
answer
17
views
React loop through an API
const [drInfo, setDrInfo] = useState([]);
function showInfo(data, index) {
if (data && data.data && data.data.length > 0) {
const doctorData = data.data[index];
...