Skip to content

Instantly share code, notes, and snippets.

@startling
Created February 18, 2012 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save startling/1858281 to your computer and use it in GitHub Desktop.
Save startling/1858281 to your computer and use it in GitHub Desktop.
constructing linked lists iteratively!
# the list so far; `tail` because we're starting at the end.
# None represents the empty list for now
tail = None
items = range(4)
# iterate through `items` backwards
for item in items[::-1]:
tail = (item, tail)
print tail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment