Hello, I have made this seemingly inefficient solution for the hangman game (not looked at the solution yet): http://pastebin.com/BPsVBGee Can anyone let me know if their is a way to condense the parts using the "q" variable? like a built in function to find out which iteration (#) you are in in the for loop?
well to start, your functions at lines 55, 64, and 73 can be helped: http://dpaste.com/1193603/ http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#building-strings-from-substrings using built-in functions to change types (string to list to tuple to string ...) is probably much faster and the string join() method is the way to build strings from lists (iterables)
Awesome, that helps a lot to make it more efficient. I also recently found the solution for the issue I was asking about with "q". You may use the built in method "enumerate" to get the list index inside the loop! for example in mine: for q, l in enumerate(letters): if l == guess: letters.pop(q) Pretty useful.
or just letters.remove(guess) or while guess in letters: letters.remove(guess)
Join our real-time social learning platform and learn together with your friends!