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 random.sample


Hi everyone, I'm working on this Challenge Question that goes like this (it's from the dungeon game): I haven't shown you how to use this function yet but I'm sure you can use it. In the random library, there's a function named sample that takes two arguments: an iterable to sample from, and an integer of how many unique samples to return. Finish the get_locations function so that it returns 3 unique values from the cells argument. I don't quite understand this question. So, what I did was to look at the documentation of random.sample(), but still, I'm not sure how this relates to the Challenge Question.

import random

def get_locations(cells):
#    pass
    return x, y, z

3 Answers

I think I got it :-) Thanks guys :-)
Here's what I did, and it passed :-)

def get_locations(cells): return random.sample(cells, 3)

Cole Wilson
Cole Wilson
7,413 Points

Nice! It's tough to decide how much to share.

Great job figuring it out!

thanks for the answer

The pass part of the function is what threw me off. It felt a little like a trick question, to be honest. Glad to be through it!

Cole Wilson
Cole Wilson
7,413 Points

Remember that you can return tuples in Python.


So all you need to do is set (x, y, z) to the output of random.sample(arg1, arg2).

arg1 and arg2 are listed as part of the question.

Actually in Conrado Landicho's he is returning a tuple.