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,710
  • 2
  • 29
  • 31
kaiseroskilo
  • 1,719
  • 4
  • 21
  • 29

1 Answers1

4

Use a dict instead.

rooms = dict(('room_%d' % x, Room(x)) for x in range(1, 6))
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358