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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:57:42+00:00 2026-06-10T18:57:42+00:00

I’m new to python, so I don’t know if this is possible. I’m trying

  • 0

I’m new to python, so I don’t know if this is possible. I’m trying to create a list of variable names from a list of strings so I can then assign values to the newly created variables.

I saw another similar question, but there was already a dict pays of keys and values.

Here’s my code:

def handy(self):
    a = raw_input('How many hands? ')
    for i in range(int(a)):
        h = "hand" + str(i+ 1)
            self.list_of_hands.append(h)
            # would like to create variable names from self.list_of_hands
            # something like "hand1 = self.do_something(i)"
            print h
    print self.list_of_hands

Given some of the answers, i’m adding the following comment:
I’m going to then assign dicts to each variable. So, can I create a dictionary of dictionaries?

  • 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-10T18:57:44+00:00Added an answer on June 10, 2026 at 6:57 pm

    Why don’t you just construct a dictionary using the strings as keys?

    >>> class test():
        def handy(self):
            a = raw_input('How many hands? ')
            d = { "hand" + str(i + 1) : self.do_something(i) for i in range(int(a)) }
    
            keys = d.keys()
            keys.sort()
            for x in keys:
                print x, '=', d[x]
    
        def do_something(self, i):
            return "something " + str(i)
    
    >>> test().handy()
    How many hands? 4
    hand1 = something 0
    hand2 = something 1
    hand3 = something 2
    hand4 = something 3
    

    Edit: You updated the question to ask if you can store a dictionary as a value in a dictionary. Yes, you can:

    >>> d = { i : { j : str(i) + str(j) for j in range(5) } for i in range(5) }
    >>> d[1][2]
    '12'
    >>> d[4][1]
    '41'
    >>> d[2]
    {0: '20', 1: '21', 2: '22', 3: '23', 4: '24'}
    >> d[5] = { 1 : '51' }
    >> d[5][1]
    '51'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't

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.