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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:41:10+00:00 2026-05-30T18:41:10+00:00

i have dict and list as bellow a = {‘aaa’: 1, ‘bbb’: 2, ‘ccc’:

  • 0

i have dict and list as bellow

a = {'aaa': 1, 'bbb': 2, 'ccc': 3}
b = ['aaa', 'bbb', 'ddd', 'eee']

I am comparing list b in dict a and I am printing values of 'aaa' and 'bbb', I dont know how to store values of aaa=1, bbb=2. I am trying using this code

for i in range(0,len(b)):
    if b[i] not in d:
        continue
    else:
        print int(a[b[i]])

its printing

1
2

i want to assign aaa=1,bbb=2,ddd=0,eee=0.

And Then when I print "print aaa,bbb,ccc,ddd" it should print values. The variables in list b can vary, so that I should dynamically assign values which are in b not in a to zero.

  • 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-30T18:41:11+00:00Added an answer on May 30, 2026 at 6:41 pm

    Try this

    a = {'aaa': 1, 'bbb': 2, 'ccc': 3}
    b = ['aaa', 'bbb', 'ddd', 'eee']
    c = dict([(x, a.get(x, 0)) for x in a])
    
    print "%(aaa)s %(bbb)s %(ccc)s" % c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have dict / list to which I can add values, just
I have a dict, which I need to pass key/values as keyword arguments.. For
I have a dictionary/list balance_sign_dict from which I need to retrieve 2 values based
I want to have sum of values in a dict. Below is the code
I have a dict as follows with unit names and testnames in a list:
I have list of dict named menu_dict_list: [{'date': datetime.datetime(2011, 8, 15, 0, 0), 'Popcorn':
I have a list of dict . Need to convert it to list of
how join tuple list a dict? this is what i have: [('a','b'),('c','d'),('e','f')] and this
i have a dict d1={'a':['in-gaap','inr',0,1],'b':['in-gaap','inr',0,2],'c':['in-ca','share',0,4],'n1':['','','','aaa']} d2={'d':['in-gaap','inr',0,'a+b'],'e':['in-gaap','inr',0,'y+t']} for k in d2.iterkeys(): a=re.findall('\w+',d2[k][3]) x2=dict([(x,d1.get(x,0)[3])for x in
I have a dict, that looks like this: { 'foo': { 'opt1': 1, 'opt2':

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.