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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:06:53+00:00 2026-05-23T11:06:53+00:00

Say I have a list list: [keith, roger, david], [5, nobody, 31], [attack, thomas,

  • 0

Say I have a list

list: [keith, roger, david], [5, nobody, 31], [attack, thomas, 4]

and a dictionary

dictionary: '55': <Trachea>, 'Roger': <Bert>

I want to delete the items in the dictionary that don’t match up with the SECOND part of the list of lists. In this example, I’d want to get rid of ’55’: but not ‘Roger’: . Thanks!

  • 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-23T11:06:54+00:00Added an answer on May 23, 2026 at 11:06 am
    #!/usr/bin/python3
    
    # myList = [['keith', 'roger', 'david'], [5, 'nobody', 31], ['attack', 'thomas', 4]]
    # myDict = {'55': '...', 'roger': '...'}
    
    secondElements = {x[1] for x in myList}
    
    filteredDict = {k:v for k,v in myDict.items() if (k in secondElements)}
    
    print(filteredDict)
    # prints: {'roger': '...'}
    

    There are quicker ways to do it, but making a set secondElements will accelerate the queries and make it O(1) time. I edited your list because there were case-sensitivity issues, but you could also use (k.lower() in secondElements).

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

Sidebar

Related Questions

Say I have a list of items from a database. Next to each item
Say I have a list x with unkown length from which I want to
Say I have a list: l = [1, 2, 3, 4] And I want
Say I have a list of files numbered 1-50 and I want to remove
let's say i have list looking like this: <select name=name id=id> <option value=10176232332>David</option> <option
Let's say I have List<Cookie> and I want to convert it to a CookieCollection
Say I have a list and a vector, and I want to zip them
Let's say I have a list l = ['michael','michael','alice','carter'] I want to map it
Lets say I have List<string> = new List<string>() {20,26,32} I want to create a
Say i have a List with items -17 Screen - 100GB HD -10788 Firewire

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.