Creating instance names from a list (Python)
Question: 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.

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.

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

    
    
    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()
    

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.

Is there a simple way of doing this? Is there a way to do this period?

\--Edit--

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;

    
    
    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()
    

Rather than build each "room" by hand, I can now...

    
    
    test = Level()
    print test.rooms['a'].size
    >>> (5,5)
    


Answer: 
    import string
    import random
    
    class Levelbuild(object):
    
      def __init__(self,min_room_count,max_room_count):
    
        rooms_temp = [new RoomBuilder() for i in range(random.randint(min_room_count,max_room_count))]
        self.l1 = dict(zip(string.ascii_lowercase, rooms_temp))
    

Note: This will fail silently if given more than 26 rooms.

