Mar-01-2019, 07:50 PM
Dear friends,
There's something in either the dict() or the random.choice() that I don't understand fully I suppose. Can you shed some light on that for me.
Thanks
There's something in either the dict() or the random.choice() that I don't understand fully I suppose. Can you shed some light on that for me.
import random capitals_dict = { 'Alabama': 'Montgomery', 'Alaska': 'Juneau', 'Arizona': 'Phoenix', 'Arkansas': 'Little Rock', 'California': 'Sacramento', 'Colorado': 'Denver', 'Connecticut': 'Hartford', 'Delaware': 'Dover', 'Florida': 'Tallahassee', 'Georgia': 'Atlanta', } states = list((capitals_dict.keys())) rand_choice = random.sample(states, 1) print (rand_choice) print(capitals_dict[rand_choice])I don't understand why this is "unmashable" as it tells me. I've of course tried to "string" the return from the random.sample() but with no luck, so there's clearly something I simply don't understand. Can you assist?
Thanks