Python Forum
extracting second values elements only in every keys in an OrderedDict
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
extracting second values elements only in every keys in an OrderedDict
#2
Straight forward with a list comprehension:
from collections import OrderedDict

regDict = OrderedDict([('glenn', (100, 200)), ('elena', (10, 20))])
second_values = [vals[1] for vals in regDict.values()]
There are other methods like using itemgetter and map.
from collections import OrderedDict
from operator import itemgetter

regDict = OrderedDict([('glenn', (100, 200)), ('elena', (10, 20))])
getter = itemgetter(1)
second_values = list(map(getter, regDict.values()))
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: extracting second values elements only in every keys in an OrderedDict - by DeaD_EyE - Nov-11-2020, 01:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,255 May-17-2022, 11:38 AM
Last Post: Larz60+
  Extracting Elements From A Website List knight2000 2 2,355 Jul-20-2021, 10:38 AM
Last Post: knight2000
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,651 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  How to escape OrderedDict as an argument? Mark17 2 2,061 Dec-23-2020, 06:47 PM
Last Post: Mark17
  Adding keys and values to a dictionary giladal 3 2,549 Nov-19-2020, 04:58 PM
Last Post: deanhystad
  AttributeError: 'collections.OrderedDict' object has no attribute 'value_counts Kristenl2784 4 7,418 Jul-17-2020, 01:50 AM
Last Post: palladium
  collections.OrderedDict Bert123456 2 1,819 Jul-09-2020, 08:51 PM
Last Post: Bert123456
  access dictionary with keys from another and write values to list redminote4dd 6 3,324 Jun-03-2020, 05:20 PM
Last Post: DeaD_EyE
  KeyError in OrderedDict rberna 1 2,156 Apr-01-2020, 04:42 AM
Last Post: perfringo
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,078 Dec-17-2019, 08:00 PM
Last Post: jasonashaw

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020