Questions tagged [ordereddict]

Python OrderedDict datatype, which remembers the order entries were added to the dictionary.

Python OrderedDict datatype, which remembers the order entries were added to the dictionary. Also see collections — High-performance container datatypes in the Python manual.

77 questions
1
vote
1 answer

Reading items from a csv and updating the same items in another csv

I'm working on a method to read data from input.csv, and update stock column in output.csv based on the product's id These are the steps I'm working on right now: 1. Read product info from input.csv into input_data = [], which will return a list of…
remus2232
  • 77
  • 7
1
vote
2 answers

How to sort a dict by the values inside its keys?

So I have something like this: [ { "arg1": {"valueone" : 2, "valuetwo": 5"}, }, { "arg2": {"valueone" : 7, "valuetwo": 3"}, }, { "arg3": {"valueone" : 3, "valuetwo": 7"}, }, { "arg4": …
webshark25
  • 15
  • 4
1
vote
4 answers

Is there a way to print a dictionary in a reverse order?

I have this ordered dict od: OrderedDict([('and', 1), ('that', 1), ('this', 1), ('of', 1), ('truly', 1), ('something', 1), ('nothing', 1), ('important', 2), ('is', 3)]) I am trying to print the key value pairs of this dictionary in the reverse…
Vignesh
  • 11
  • 2
1
vote
1 answer

Keeping the order of an OrderedDict

I have an OrderedDict that I'm passing to a function. Somewhere in the function it changes the ordering, though I'm not sure why and am trying to debug it. Here is an example of the function and the function and output: def unnest_data(data): …
user10503628
1
vote
1 answer

How do I dump an OrderedDict out as a YAML file?

I wrote a simple script that I finally use ruamel.yaml to publish out to a YAML file (example shown below). I used collections.OrderedDict so that I can alphabetically reorder the keys, but even after re-ordering and converting it back to a…
1
vote
3 answers

how to order a dictionary based on key by daywise in python

I had 2 list daydate=['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] percentday=['0%', '17%', '27%', '11%', '7%', '19%', '19%'] i have converted into dictionary by doing daydic=dict(zip(daydate, percentday)) the…
vtustudent
  • 103
  • 7
1
vote
1 answer

Python 2 csv.DictWriter() Unicode Encode exception handling

My code below: with open('C:\\Users\\...\\Documents\\RP_test_8.txt', 'w') as f: cf = csv.DictWriter(f, column_headers, extrasaction='ignore') cf.writeheader() cf.writerows(r.data for r in records) gives me a unicode encode…
Y. Eman
  • 23
  • 9
0
votes
2 answers

How to create dataframe from ordered dictionary?

I have an ordered dictionary which has 4 keys and multiple values. I tried to create the dataframe like this df = pd.DataFrame(items, index=[0]) print('\ndf is ',df) But this triggers ValueError, as the multiple values from the dictionary don't…
0
votes
1 answer

How can I update the value of key in OrderedDict in Python 3?

Here's a minimal reproducible example: from collections import OrderedDict d = OrderedDict([('foo', 123), ('bar', 456)]) So I want to check if there's a foo key in d and if there's then I'd like to rewrite it as a single value of…
0
votes
1 answer

Dagster pass ordered dict in the config schema

How can I pass an Ordered Dict in Dagster solid's config schema? The simple thing: from dagster import solid, execute_solid, Field @solid(config_schema={'my_dict': Field(dict, is_required=True)}) def test_ordered_dict(context): …
cyau
  • 125
  • 6
0
votes
0 answers

Do I still need to use an Ordered Dictionary?

So, I was wondering if I still needed to use an Ordered Dictionary for this. import requests import time import collections import threading class LiveChecker: """Editable YT streamer checker. Meant to be used with a discord bot. Edit the…
0
votes
1 answer

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 order of the sentence. from collections import…
Y4RD13
  • 607
  • 6
  • 24
0
votes
1 answer

Does Python[3.6+] built-in Dictionary have any function similar to OrderedDict's move_to_end()

I was looking at the solution for LRU cache implementation on leetcode. And the built-in dict is also ordered from Python 3.6+. I was wondering if there is any function similar to OrderedDict's move_to_end() which I can use with built-in dict and…
0
votes
1 answer

How to convert an ordered dict into a pandas dataframe with each key value ('label') for each column

How to convert an ordered dict into a pandas dataframe with each key ('label') for each column. ```OderedDict = [OrderedDict([('dataCells', [OrderedDict([('label', 'BT Ltd'), ('value',…
mtm1186
  • 11
  • 3
0
votes
2 answers

How do I slice an OrderedDict?

I tried slicing an OrderedDict like this: for key in some_dict[:10]: But I get a TypeError saying "unhashable type: 'slice'". How do I get this dictionary's first 10 key-value pairs?