Last active
August 29, 2015 14:06
-
-
Save MarcelCutts/ce88f596e173d9cc8514 to your computer and use it in GitHub Desktop.
Comparing classic with functional approaches to looking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print the top board markers | |
# Starting with a space and climbing alphabetically | |
# Classic method | |
current_row = "A" | |
top_line = " " | |
for column in self.grid[0]: | |
top_line += current_row + " " | |
current_row = chr(ord(current_row)+1) | |
print top_line | |
# Functional method | |
current_row = "A" | |
letters = map(lambda x: chr(ord(current_row)+x), range(0, len(self.grid[0]))) | |
print " " + " ".join(letters) | |
# Both output " A B C D E" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment