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 8216217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:03:11+00:00 2026-06-07T12:03:11+00:00

I have a dict that looks like this db = { ‘ObjectID’: [‘-1’, ‘6’,

  • 0

I have a dict that looks like this

db = {
'ObjectID': ['-1', '6', '10', '13', '13', '13', '-1', '-1', '-1', '-1', '-1', '-1'], 
'Test_value': ['25', '0,28999999', '100,00000000', 'Geometry', '126641,847400000000', '473106,185600000030', ' ', ' ', ' ', ' ', ' ', ' '], 
'Has_error': ['true', 'true', 'true', 'true', 'true', 'true', 'false', 'false', 'false', 'false', 'false', 'false'], 
'Message': ['Table row counts are different', 'ObjectID 6 is different for Field DIKTE_BRUGDEK', 'ObjectID 10 is different for Field RICHTING_1',                'ObjectID 13 is different for Field GEOMETRIE', 'ObjectID 13 is different for Field X', 'ObjectID 13 is different for Field Y', 'Shape types are the          same', 'Feature types are the same', 'Feature class extents are the same', 'GeometryDefs are the same', 'Field properties are the same', 'Spatial             references are the same'], 'Identifier': ['Table', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'FeatureClass',            'FeatureClass', 'FeatureClass', 'GeometryDef', 'Field', 'SpatialReference'], 
'Base_value': ['23', '0,19000000', '394,00000000', 'Geometry', '126530,700000000000', '473095,700000000010', ' ', ' ', ' ', ' ', ' ', ' ']}

I want to to break it down into a smaller subset based on the entries in the list of ‘ObjectID’, namely -1.
My first attempt was to built an index of the values, like:

filter_ind = []
for k,v in db.iteritems():
    for i in xrange(len(v)):
            if (k == 'ObjectID') and (int(v[i]) != -1):
                filter_ind.append(i) 

Then I tried to build a new dict, using filter_ind as a sort filter:
dict((k,v[i]) for i in filter_ind for k, v in db.iteritems())

What I get is only the last match as v isn’t a list anymore:
{'ObjectID':'13','Test_value':'473106,185600000030','Has_error':'true',
'Message':'ObjectID 13 is different for Field Y',
'Identifier':'FeatureClass','Base_value': '473095,700000000010'}

Question: is there another way to filter a dict based on certain value within itself? If this is considered a relatively straigh forward approach, what is a smart way to use the index as filter to create a new dict? Thanks already.

  • 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-06-07T12:03:12+00:00Added an answer on June 7, 2026 at 12:03 pm

    I think you’re overcomplicating this a bit. First, there’s no need for the nested loops. You can get the indices you want this way:

    oids = db['ObjectID']
    for i, id in enumerate(oids):
        if id != -1
            filter_ind.append(i) 
    

    Or more tersely,

    filter_ind = [i for i, id in enumerate(oids) if id != '-1']
    

    Then you could use the ids to filter the individual lists:

    dict((key, [val[i] for i in filter_ind]) for key, val in db.iteritems())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rowset that looks like this: defaultdict(<type 'dict'>, { u'row1': {u'column1': 33,
I have a plist that looks like this: <dict> <key>Aaron</key> <dict> <key>number</key> <string>1234</string> <key>country</key>
I have a dict that looks like this { keyword1:3 , keyword2:1 , keyword3:5
I have a very large defaultdict(dict) that looks something like this: data['w']['x']['y']['z']={'a':5,'b':10} I'm trying
I have a .plist file that looks like this: <plist version=1.0> <array> <dict> <key>name</key>
I have a dict, that looks like this: { 'foo': { 'opt1': 1, 'opt2':
I have a dict of configuration variables that looks something like this: self.config =
I have a list of dictionaries that looks like this: [{'id':1,'name':'Foo'},{'id':2,'name':'Bar'}] I'd like to
I have a message definition file that looks like this struct1 { field=name type=string
Say I have a string that looks like this: str = The &yquick &cbrown

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.