-1

What I have tried is

answer = "'You need to enter one alphabetic character which you haven't\
already guessed. Try again'"

counter = 0

p = [x.lower() for x in past_guesses]

if len(p) != (set(past_guesses)):
    result = answer
else:
    result = 'Good guess'
return result

As expected any duplicate letters should fail, returning the answer, and any that don't contain duplicate letters should pass, however for the input ([A, b]) I am getting the return for a duplicate.

Anyone know why and how this can be fixed?

eyllanesc
  • 221,139
  • 17
  • 121
  • 189
  • 3
    Not sure what you mean by "input" - there is neither a stdin input, nor is it a function with parameters... but I believe you might be missing a `len` in your `if`? – Amadan Oct 23 '18 at 04:06
  • should there be a len in front of (set(past_guesses))? – Meliodus123 Oct 23 '18 at 04:10
  • More specifically, you probably want this `if len(p) != len(set(past_guesses)):` – slider Oct 23 '18 at 04:11
  • Even then im getting the same answer, for past_guesses i input (['A', 'b']) and got answer instead of 'Good guess' – Meliodus123 Oct 23 '18 at 04:13
  • Works fine for me (I see "Good guess"): https://trinket.io/python/638e377cf1 – slider Oct 23 '18 at 04:17
  • Oh i see my mistake, i need to set it to the changed list not the original list. – Meliodus123 Oct 23 '18 at 04:17
  • Possible duplicate of [How to check if a list contains duplicate items?](https://stackoverflow.com/questions/48209673/how-to-check-if-a-list-contains-duplicate-items) – Rarblack Oct 23 '18 at 04:37

1 Answers1

0

Your code has a lacking place in if condition. You are trying to compare the length of set and list but unfortunately you have forgotten.

Add len() to your code:

if len(p) != len(set(past_guesses)):
Rarblack
  • 4,396
  • 4
  • 20
  • 32