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 Movement

David Welsh
David Welsh
9,298 Points

Syntax questions for Dungeon Maze Game

I have a couple of questions that may have come up in previous videos, but if they did, I don't recall them. First, in the while loop when you are formatting the print statement "you can move {}", what does the ", " do in format(", ".join(valid_moves))). LINE 56 for me

Also, if tuples are immutable, how can we use them for our ever changing x and y coordinates? I understand why CELLS is a list of tuples, since you wouldn't want that to change, but when the videos on this first started, I would have assumed that the x and y coordinates would have been list or something mutable. **The code I am referring to is: def move_player(player, move): x, y = player if move == "LEFT": x-=1

etc..

2 Answers

Omar Farag
Omar Farag
4,573 Points

",".join(var) joins all the items with the character in between the parentheses. For example,

my_list = ['a', 'b', 'c']
", ".join(my_list)
my_lsit = 'a, b, c'

if you did not put anything in between the parentheses, it would join with nothing in between. As for changing the tuple, you aren't. You are simply unpacking the tuple, changing the values of the unpacked values, and then putting it back into a tuple. You then compare the tuple to a cell in the CELLS variable, and put the player in that location. Hope this helped.

David Welsh
David Welsh
9,298 Points

Thank you, I appreciate it. I'm not sure why I data-dumped how to use join, but as soon as I saw your response, I knew where I went wrong. Thank you.