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 (2016, retired 2019) Dungeon Game Dungeon Entrance

Flore W
Flore W
4,744 Points

In the Dungeon Game, Kenneth mentions that CELLS could be a tuple instead of a list of tuples. What would it look like?

Does he mean it would be something like (x, y) with x and y being variables?

3 Answers

Yes, you can have a tuple of tuples as you have highlighted above. I am no expert in Python but I dont this gains you much over a list of tuples.

One thing maybe of benefit is that Tuples are immutable (cant be changed) therefore given that we have fixed set of cells, using a Tuple means that we could not inadevertenly change something., Also tuples are meant to perform better than lists....

Iulia Maria Lungu
Iulia Maria Lungu
17,546 Points

I tried myself to use tuple instead of list. It actually makes sense because that should be a immutable. We don't want to change the CELLS. It's supposed to be constant. I've seen random lib sample works with tuples as well. from the docs: random.sample(population, k) for instance if you feed a dictionary to the random.sample you get an error:

Population must be a sequence or set

So your

CELLS = ((0,0),(0,1),(0,2),
            (1,0),(1,1),(1,2),
            (2,0),(2,1),(2.2))

makes total sense, just that the final cell has a float in it instead of a tuple

Hi there, yes the cells could look like the following

CELLS = [(0,0),(0,1),(0,2),
            (1,0),(1,1),(1,2),
            (2,0),(2,1),(2.2)]  
Flore W
Flore W
4,744 Points

Hey Stuart, that's a list of tuples, I was more wondering what it would look like as a tuple since Kenneth mentioned it. Could CELLS look like:

CELLS = ((0,0),(0,1),(0,2),
            (1,0),(1,1),(1,2),
            (2,0),(2,1),(2.2)) 

and what would be the difference?