Skip to content

Instantly share code, notes, and snippets.

@MarcelCutts
Last active August 29, 2015 14:06
Show Gist options
  • Save MarcelCutts/ce88f596e173d9cc8514 to your computer and use it in GitHub Desktop.
Save MarcelCutts/ce88f596e173d9cc8514 to your computer and use it in GitHub Desktop.
Comparing classic with functional approaches to looking
# 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