0

I'm trying to code a console minigame (for fun), and I need to create a map(graph) with a predefined number of rooms(vertices).

I'd like to define a class room and create instances of that class that will be assigned to variable names like room_1, room_2 and so on.

My problem is, that I don't know how to create these variable names. To cut a long story short, I need a tool/tip/trick to create preformated variable names on demand.

F.i let's say that MAX_R=5, then I'll need variables room_1 to room_5. Any ideas?

Stan
  • 8,292
  • 2
  • 27
  • 30
kaiseroskilo
  • 1,699
  • 4
  • 20
  • 29

1 Answers1

4

Use a dict instead.

rooms = dict(('room_%d' % x, Room(x)) for x in range(1, 6))
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325