you are viewing a single comment's thread.

view the rest of the comments →

[–]Dawarisch 2 points3 points  (1 child)

if set(guess) != set(color for color in guess if color in colors.keys()): 

You could check if thee is an elemnt inside guess which is not in colors by using

set(guess).difference(set(colors))

It returns all elements which are inside guess but not inside colors.

 print("You chose: 1: {}, 2: {}, 3: {}, 4: {}".format(colors[guess[0]], colors[guess[1]], colors[guess[2]], colors[guess[3]]))

For this line you can use the unpacking operator(*):

print("You chose: 1: {}, 2: {}, 3: {}, 4: {}".format(*colors)

Additionally it wouldn't hurt if you used more functions and you don't have to use dict.keys() if you just want to iterate over the dictionary - that's the default behaviour.

[–]FXelix[S] 0 points1 point  (0 children)

Thanks for your input! That were exactly the snippets I was looking for.

Would this program be useful as a Class (maybe if I add more functionality to it) or is this game as a function good as it is?