Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:07:24+00:00 2026-05-29T11:07:24+00:00

I am trying to get all values (except corresponding to a particular key) from

  • 0

I am trying to get all values (except corresponding to a particular key) from a list of dicts by doing this:

fv = [[v for (k,v) in d.iteritems() if k is not 'xKey'] for d in someDict] 

where someDict is like:

[{xKey:0.1,yKey:0.2,zKey:0.3},{yKey:0.9,xKey:0.7,zKey:0.4}...]

I know a dict doesn’t have an inherent order. But my list of lists fv needs to have the values in order. I am thinking about sorting the dict on key and then doing what I just did. But is that guaranteed to work?

I know using OrderedDict is an option but it also seems to have inferior performance as compared to dict, which would be a concern for me since my dictionary is typically going to have huge amount of data.

Update : When I say I need values in order, they don’t really have to be sorted.What I mean is I need to be able to retrieve the list of values in a fixed deterministic order each time.In the above example, I always want to get [[0.2,0.3],[0.9,0.4]] although it may not be a sorted order per se. Sorting would enforce one deterministic order.What I really care about is maintaining the position of values in the final list.e.g. Value of yKey must always be the first value in each list, the value of zKey must always be the second value in each list and so on even though ykey, zkey etc may be in any order in the dictionary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:07:25+00:00Added an answer on May 29, 2026 at 11:07 am

    If you know the list of possible keys that your dicts may contain, the following solution might work for you:

    allkeys = ...  # might be known; or obtained from available dicts by union;
                   # 'xKey' can be removed at this stage to simplify the list
                   # comprehension that follows
    sortedKeys = sorted(allKeys)
    list_of_values = [[d.get(k) for k in sortedKeys if k in d]
                                                       for d in list_of_dicts] 
    

    It might be slower than iteritems though. The if k in d part can be removed if all the dicts contain the same set of keys.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get all property names / values from an Outlook item. I
iam trying to get all object's xpath's from loaded page via selenium something similar
I am trying to get all the rows that exist in allData but not
I'm trying to get all the input elements from a certain form from jQuery
I'm trying to get all the sublists that don't inherit from a specified class
I am trying to get all of the video elements and their attributes from
I'm trying to do this SELECT `Name`,`Value` FROM `Constants` WHERE `Name` NOT IN ('Do
I've been trying to get this to work for a while, and all the
I am using GWT ext and trying to get the values from page and
I'm trying to get all the direct reports of a User through Active Directory,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.