Creating instance names from a list (Python)
<p>I've got a function that builds a random number of object instances. For the sake of demonstrating the general idea, we're going to pretend that this is an algorithm to build a series of nethack-like rooms.</p>

<p>The requirements are such that I won't know how many instances there will be in advance; these are generated randomly and on-the-fly.</p>

<p>As a brief note: I am fully aware that the following code is nonfunctional, but it should (hopefully!) demonstrate my aims.</p>

<pre><code>import random

class Levelbuild(object):

    def __init__(self):
        self.l1 = dict({0:'a',1:'b',2:'c',3:'d',4:'e',5:'f',6:'g',7:'h',8:'i'})
        # Pick a random number between 4 and 9.
        for i in range(random.randint(4,9)):
            self.l1[i] = Roombuilder()
</code></pre>

<p>If we assume that the chosen random integer is 5, the ideal result would be 5 Roombuilder() instances; labeled a, b, c, d, and e, respectively.</p>

<p>Is there a simple way of doing this? Is there a way to do this period?</p>

<p>--Edit--</p>

<p>A giant "thank you" to Nick ODell for his answer. This isn't a complete copy/paste-- but it's a variation that works for what I need;</p>

<pre><code>import random

class Room(object):
    def __init__(self):
        self.size = (5,5)

class Level(object):

    def __init__(self):
        roomnames = ['a','b','c','d','e','f','g','h','i']
        self.rooms = {}
        for i in range(random.randint(4, 9)):
            self.rooms[roomnames[i]] = Room()
</code></pre>

<p>Rather than build each "room" by hand, I can now...</p>

<pre><code>test = Level()
print test.rooms['a'].size
&gt;&gt;&gt; (5,5)
</code></pre>
