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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:30:27+00:00 2026-06-17T19:30:27+00:00

I am new to python and programming in general. I looked at a lot

  • 0

I am new to python and programming in general. I looked at a lot of questions about dictionaries, lists, map, lambda, list comprehensions, etc., but I cannot seem to put a specific function together to build the dictionary that I want.

I can describe the dictionary that I want to produce as follows:

    #goal: make a dictionary that describes a form

    FORMNAME = 'aspnetForm'
    nicks = ['username','password','submit'] #nicknames I want to use
    names = [FIELD_USERNAME, FIELD_PWD, BUTTON_LOGIN] #field names
    values =  ['myusername','mypass',''] #field values
    types =  ['text', 'password', 'submit'] #control types

    INPUTS = [{nicks[0]:{'name':names[0],'value':values[0],'type':types[0]}},
    {nicks[1]:{'name':names[1],'value':values[1],'type':types[1]}},
    {nicks[2]:{'name':names[2],'value':values[2],'type':types[2]}}]

    LOGINFORM = {'name':FORMNAME, 'input':INPUTS} #this is the final dictionary I want to build

Please, impress me with the simplicity and elegance of the best python method to build LOGINFORM so that I may learn!

I want to use this dictionary to populate a form in mechanize. It’s the only form I need to populate. I can populate this form the “long” way, but I wanted to learn how to populate it in a systematic way with a dictionary.

My main purpose here is to learn how to populate dictionaries. But I thank you in advance for not suggesting a better way until I learn how to answer my own question.

  • 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-17T19:30:29+00:00Added an answer on June 17, 2026 at 7:30 pm

    You can make use of zip:

    LOGINFORM = {'name': FORMNAME, 'input':
         [{nick: {'name': name, 'value': value, 'type': sort}}
           for nick, name, value, sort in zip(nicks, names, values, types)]}
    

    I’m avoiding the use of type as variable name, because it’s a builtin function/type, but actually you can use it here just fine.

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

Sidebar

Related Questions

Brand new to Python (and programming in general), if this is simple and/or answered
I'm pretty new to Python and programming in general, and I was wondering if
I'm new to Python and to programming in general. I've installed BioPython in hopes
New to Python and programming in general. I want to install a module from
I am very new to Python/Django and programming in general. With the limited tools
I'm very new to Python and multithreaded programming in general. Basically, I have a
I'm new to python and programming in general, so would really appreciate any clarification
I'm new to Python and programming in general (a couple of weeks at most).
I'm fairly new to Python and programming in general. I have done a few
I am somewhat new to Python and programming in general so I apologize. By

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.