Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (Retired) Dungeon Game Planning Our Dungeon

peter keves
peter keves
6,854 Points

why do we use tuples to represent cordinates ? can't we just use lists for that as well ?

why do we use tuples to represent cordinates ? can't we just use lists for that as well ?

3 Answers

Yes, you can. But it's a lot safer to use tuples, which, unlike lists, are immutable. You cannot use methods or index notation to easily add/change/remove elements when using tuples.

Travis Golob
Travis Golob
8,794 Points

These coordinates will never change through the duration of the game. Room (1, 2) will always be room (1, 2). We store this as a Tuple so the program (or programer ;) ) doesn't actually change it at some point. It makes debugging a whole lot easier.

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

You can use list of lists, creating a map or world of a game.

world = []

for item in range(3):
    world.append(["O"] * 3)

then you can print your world:

def showworld(world):
    for level in world:
        print(" ".join(level))

Coordinates are very representative this way.