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

The Archive Base Latest Questions

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

When I do dict = {‘Alice’: ‘7898’, ‘Beth’: ‘9102’, ‘Cecil’: ‘3258’} print filter(lambda x:

  • 0

When I do

dict = {'Alice': '7898', 'Beth': '9102', 'Cecil': '3258'}
print filter(lambda x: x, dict['Alice'])

it shows: 7898

When I do the next

dict = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'}
print filter(lambda x: x=="2341", dict['Alice'])

it shows:

Why it doesn’t show True. How to get True ?

  • 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-23T04:53:47+00:00Added an answer on May 23, 2026 at 4:53 am

    It looks like your misunderstanding is with filter, to me. You pass a predicate function and an iterable object to filter. It creates a new object containing those items from the first iterable for which the predicate returns a true value (not necessarily True itself, just something that tests as true). The iterable in the two cases is the string '2341', which means the individual letters are tested. Of course the string '2341' is not equal to any of '2', ‘3', '4', or '1'.

    Try it with a tuple and it’s easier to see what’s going on:

    >>> tup = tuple(dict['Alice'])
    >>> tup
    ('7', '8', '9', '8')
    >>> filter(lambda x: x, tup)
    ('7', '8', '9', '8')
    >>> tup
    ('7', '8', '9', '8')
    >>> filter(lambda x: x, tup)
    ('7', '8', '9', '8')
    >>> filter(lambda x: x=="2341", tup)
    ()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this dict in python; d={} d['b']='beta' d['g']='gamma' d['a']='alpha' when i print the
I have a dict of dicts: for i in results[2]: print i Recurring: {'p_pnref':
class Meta(dict): def __init__(self, indexed, method, *args, **kwargs): super(Meta, self).__init__(*args, **kwargs) print self How
dict methods dict.keys() , dict.items() and dict.values() return views instead of lists. Source First
I have a dict, that looks like this: { 'foo': { 'opt1': 1, 'opt2':
I have a dict, which I need to pass key/values as keyword arguments.. For
When you call dict.values() the order of the returned items is dependent on the
i've got a dict generated at somewhere like this: d={ 'k1':'v1', 'k2':'v2', ... }
I know that Python dict s will leak when items are removed (because the
class attrdict(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) self.__dict__ = self a =

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.