Questions tagged [ordereddictionary]
A collection of key-value pairs also accessible by insertion-order.
503
questions
0
votes
1answer
33 views
Flattening and combining parts of an ordered dictionary
I have taken an xml file and changed it to an ordered dict with xmltodict. It looks something like this:
XML file
<part_report>
<metadata>
<data1>apple</data1>
...
0
votes
0answers
28 views
Incorporating item grab from dictionary array
This is the code I have for a text game I am creating where I have set up dict to navigate between rooms. There is an item in each of the rooms the user is tasked with collecting, and I am look for ...
-1
votes
1answer
26 views
How to sort a dictionary of nested lists by value with one key ascending and one key descending?
I'm working on a problem that states the following:
Write a function telling apart accepted and refused students according to a threshold.
The function should be called select_student and takes as ...
0
votes
1answer
27 views
Pythonic Way of Lexicographically Sorting Keys of an OrderedDict On Insert
I have the following class that keeps track of an OrderedDict:
class LexDict:
def __init__(self):
self.m_map = OrderedDict() # maps string which is case-sensitive to int
def set(self,...
0
votes
1answer
22 views
How to make a zipped OrderedDict with multiple lists based on a sentence?
I have six list, three of them correspond to the given sentence and the other three lists correspond to the labels of the previous lists. I want to zip these lists into an OrderedDict, based on the ...
0
votes
0answers
22 views
Enum.filter change type from dict to ordered dict [duplicate]
I run following code:
iex(1)> %{a: 1, b: nil} |> Enum.filter(fn {_key, value} -> !is_nil(value) end)
[a: 1]
But I expect to see %{a: 1} What kind of concept is behind this? How can I ...
0
votes
0answers
17 views
Get values from a list of keys after the keys are set as columns
How to get the actual values of the keys from this previous question?
How to pack multilines results (OrderedDict with differents keys) into pandas dataframe?
list_of_ordered_dicts = [od1,od2,od3]
...
0
votes
2answers
39 views
Extract values from a list and create nested dictionary using python
I am trying to extract values from a list and populate it in a nested dictionary.
Input:
['abc-bcd_10_01_physics_90_70_20',
'abc-bcd_10_01_chemistry_85_75_10',
'ac-bd_10_03_biology_60_50_10',
'ad-...
0
votes
0answers
14 views
It is okay to remove the OrderedDict in class OrderedCounter(Counter, OrderedDict): in python 3.8?
I am new in Python and studying collections module. I saw this code in w3source:
from collections import Counter, OrderedDict
class OrderedCounter(Counter, OrderedDict):
pass
word_array = []
n = ...
1
vote
1answer
64 views
Get value of an OrderedDictionary
I cannot manage to find values from my OrderedDictionary, I was following several posts on the stack, so I don't see what I am not doing good?
private List<IfcElement> readListParamFromList(...
1
vote
1answer
39 views
Python Dictionary - Looping issue (nested) | TypeError: list indices must be integers or slices, not str
I am trying to loop over a nested dictionary but keep getting the error: list indices must be integers or slices, not str.
This is the data I am trying to loop over and have converted to a dictionary ...
-2
votes
1answer
91 views
How to avoid duplicate keys error in Dictionary?
To give some background, I am building an Evil Hangman game. I have a long list of words selected by length. I ask the user for a letter input, and remove words from the list if they don't contain ...
1
vote
4answers
68 views
How to update dictionary key based on value?
I have two dictionaries with similar values, but different keys. I'd like to update the second dictionary db with the key value of the first dictionary user.
What would be the optimal way to do that ...
1
vote
1answer
73 views
Error cannot unpack non-iterable when trying to Iterate over OrderedDict()
I'm trying to iterate over a OrderedDict on python 3.9 but when I'm getting:
for key, value in d:
TypeError: cannot unpack non-iterable int object execute the for bucle
Here is my code:
MAXSIZE = 5
...
2
votes
1answer
23 views
How to minimize distances in ordered dictionary containing only backward references to the keys?
I have an ordered dictionary containing non-cyclical references to other elements in the dictionary:
from collections import OrderedDict
ug = OrderedDict(a=[],b=['e'],c=['a','b'],d=['a'],e=[])
Now I ...
0
votes
2answers
25 views
Retrieve value of certain key for every item in an ordered dictionary
Am having a hard time retrieving the value of name in every items in an ordered list like below any help would be highly appreciated.
OrderedDict([('12345', {'buyingprice': '600', 'category': 'Dairy', ...
1
vote
1answer
27 views
Sorting a list of ordered dictionaries in Pandas for csv output
I have added a dbf file into a Pandas series dataframe. The original data is in a listed dictionary like so.
0 {'a': 'av1','b': 'bv1', 'c' : 'cv1',...
1 {'a': 'av2', b': 'bv2', 'c' : 'cv2',...
-3
votes
1answer
58 views
ordered dict into another dict
I need to order the dict by the value into another dict as below
dict_filtro = {"Conector 1":{"alasca":30,"USA":10,"Brasil":20},
"Conector ...
0
votes
1answer
44 views
Is there a way to retrieve the index of an item stored within C#s' OrderedDictionary DS in O(1)~ complexity
In other words - how do I get it without iterating over "GetEnumerator()"s value (O(n))?
for example, lets say I've created the following ordered dictionary (named aOrdDict), which contains ...
0
votes
0answers
34 views
Creating a range of consecutive IP addresses from a text list
I'm working on developing a Python script that will perform a hostname to IP address nslookup when provided a file, 'hosts.txt', that contains a list of hostnames on our network. The end goal is to ...
2
votes
1answer
287 views
AttributeError: 'collections.OrderedDict' object has no attribute 'train'
with summary_writer.as_default():
for round_num in range(1, NUM_ROUNDS):
state, metrics = iterative_process.next(state, federated_train_data)
# for name, value in metrics.train._asdict()....
5
votes
3answers
182 views
How to reorder the keys of a dictionary?
I have multiple dictionaries inside the list. I want to sort the dictionary with the custom key. In my case, I want to sort it using Date key. By that, I mean to move the Date key to the first ...
-1
votes
1answer
31 views
Print only the final value of incremented integer in Python
I have this code in Python where I increment an integer every time I find a specific packet. I want to print in the end the final value of the integer, but python prints me all the values that the ...
1
vote
3answers
68 views
Save an OrderedDict Object to a csv file
I have the following object that is an OrderedDict that I would like to export to csv.
OrderedDict([('AGG', 0.09888),
('BWX', 0.04886),
('DBC', 0.06046),
('EMB', ...
1
vote
1answer
51 views
How do I open a list of txt files, convert them to strings, and then see if they match any keys from a given dictionary [closed]
I have a list of text files (list_4), of the format cv1.txt, cv2.txt, cv3.txt etc, up to cv20.txt. I want to use a for loop to open and read these files indivdually and convert them into strings. This ...
1
vote
2answers
33 views
Multi-level dictionary structure from DataFrame
I want to create a multi-layer dictionary from a DataFrame, in a specific data format.
Generic Input, with Date as string (immutable):
cleaned['Date'] = cleaned['Date'].astype(str)
cleaned.tail(3)
...
0
votes
1answer
47 views
searching for a list in a list of ordered dictionaries
So I have a list of ordered dictionaries which all have 'name' keys which take a string as a value and then a series of other keys which take integers as values. I also have a list of integers ...
1
vote
1answer
44 views
YAML mapping order not preserved when using alias and yamlordereddictloader loader
I want to load a YAML file into Python as an OrderedDict. I am using yamlordereddictloader to preserve ordering.
However, I notice that the aliased object is placed "too soon" in the ...
0
votes
1answer
61 views
How to filter out item from ordered dict
For the following list of ordered dictionary items,
{"HOTEL_SURVEY_LIST": [ {"room_type":"single","resource_index":3,"room_id":"room0","...
-1
votes
1answer
61 views
python: efficient way to get an item by numerical index from an OrderedDict
Is there a way to implement an equivalent of the item method shown below, which gives the same functionality without copying all the data or looping? So in this example it would return ('bar', 20).
...
0
votes
0answers
35 views
Filter Nested Ordered Dict from value list python
I have an ordered dict and need to filter all rows that match the following unique id's:
array([111, 335], dtype=int64)
Looking to look like:
OrderedDict([('UniqueID',
masked_array(data=[...
0
votes
1answer
25 views
How to replace values in an ordered dictionary
I am reading in an example file as an ordered dictionary and want to replace some text ('xx' with '' or or null).I am struggling to understand how to do this.I have tried different methods and ended ...
0
votes
0answers
131 views
Flatten multi level nested dictionary in Python
I have a multi level nested dictionary and trying to make a pandas dataframe out of it. The code below works fine up to level n-1. Unfortunately the last level still remains an OrderedDict[]. For ...
0
votes
2answers
83 views
How would I update each dataframe in orderedDict?
I have an excel file of three sheets:
Sheet1:
name fav date
blue 5 11/20/2020
orange 5 11/20/2020
red 5 11/20/2020
sheet 2 and 3 follows the same format (same column names ...
1
vote
1answer
70 views
python: how to add a key-value pair to the beginning of a nested dictionary?
i need to add to the beginning of a nested dictionary. it looks like move_to_end() is the easiest way for us to accomplish this but it seems that i cannot use this in a nested dictionary.
dict = ...
0
votes
0answers
12 views
Ordered dictionaries Python 3.6.5
I am trying to preserve insertion order on a dictionary, I am using a for loop to insert elements. I tried using collections ordereddict but it does not seem to do the trick. How can I solve this ?
...
2
votes
2answers
183 views
Can I flatten a deeply nested Python dictionary which contains values with lists of more nested dictionaries?
I am working with a large xml file in which I have been trying to extract keys and values. The information in this file is very sensitive so I cannot share it. I started by using the xml library. ...
0
votes
1answer
70 views
Iterating on an Ordered Dictionary results in: 'float' object has no attribute 'items'
I have the following function that prints out an ordered dictionary:
def printSQN(analyzer):
sqn = round(analyzer.sqn, 2)
print(f'The System Quality Number (SQN) is: {sqn}')
The output looks ...
0
votes
1answer
39 views
How do you find the first item in a dictionary? [duplicate]
I am trying to get the first item I inserted in my dictionary (which hasn't been re-ordered).
For instance:
_dict = {'a':1, 'b':2, 'c':3}
I would like to get the tuple ('a',1)
How can I do that?
0
votes
2answers
40 views
Sort a PowerShell OrderedDictionary with custom objects
I have created an OrderedDictionary filled with custom objects. Each object has two properties:
$myCustomObject.name = "foo"
$myCustomObject.date = <datetime here>
$orderedDictionary.add(<...
1
vote
3answers
59 views
How do I extract specific values from an OrderedDict?
I like to extract specific keys and store them onto a list. So far, I am able to read from MariaDB and store the rows as a dictionary (I prefer to have the output as JSON):
import pymysql
import ...
-1
votes
1answer
90 views
Python 3 filter list of ordered dict items by a specific key value
I am iterating a list of other list variables to an ordered dictionary variable and appending them to a new list variable. I am trying to filter the new ordered dict entries to only get the results ...
0
votes
2answers
88 views
Find items that appear together on multiple lists
I am trying to write some efficient python code that will identify items that appear together on multiple lists. For example, in the dictionary of lists
list_of_lists = {'lista':list('abcdefhmqr'),
...
-4
votes
1answer
35 views
Multiple value for one key [duplicate]
I want to put multiple values in a list in the dictionary that has on key.
For example,
time = {"created":123, "created":456, "created":799}
print (time['created'])
it will print just the last ...
1
vote
2answers
50 views
How to find a key value from a key value match?
I have a really long ordered dict that looks similar to this:
OrderedDict([('JIRAUSER16100', {'name': 'john.smith', 'fullname': 'John Smith', 'email': 'John.Smith@domain.test', 'active': True}), ('...
1
vote
1answer
520 views
Typescript Ordered Dictionary
I need to store relatively big amount of data sorted with index, something similar to editable chat - ordered by time and with random access for editing.
The number of items are relatively big and ...
3
votes
2answers
71 views
Reverse the order of elements in a dictionary
If I have a dictionary dict1 = {1:'a', 2:'c', 'd':'gh'}
and I want to reverse it so that dict2 = {'d':'gh', 2:'c', 1:'a'}. I do not want to change the maping of the dictionary.
I an doing this in ...
0
votes
0answers
41 views
Python sorting an ordered dictionary and the resulting .items() iterator
How to sort an OrderedDict definitely does exist elsewhere on the site. An example of how to do this is:
foo = OrderedDict(sorted(ordered_dict.items(), key=lambda x: x[1][0]))
To explain, I have an ...
-1
votes
1answer
90 views
How to write OrderedDict into netcdf with python netcdf4?
I resampled NetCDF data and organized in OrderedDict(This is the original organization of original data).
But when I use the following script to write it in a new netcdf file:
ncout.createDimension('...
0
votes
1answer
76 views
How to convert a list of tuples to a csv file
Very new to programming and was trying to create an amortization table. Found some great questions and answers on here, but now I am stuck trying to convert the results into a csv file.
from ...