Skip to content

Instantly share code, notes, and snippets.

@liavkoren
Last active December 24, 2016 21:31
Show Gist options
  • Save liavkoren/c4b941c58a9e0c7f0260b2b4591348f4 to your computer and use it in GitHub Desktop.
Save liavkoren/c4b941c58a9e0c7f0260b2b4591348f4 to your computer and use it in GitHub Desktop.
# A dictionary comprehension:
a = {num: Node(num) for num in range(1, 8)}
```
a now looks like:
{1: Node(data=1, next_node=None),
2: Node(data=2, next_node=None),
3: Node(data=3, next_node=None),
4: Node(data=4, next_node=None),
5: Node(data=5, next_node=None),
6: Node(data=6, next_node=None),
7: Node(data=7, next_node=None)}
```
build a linked list:
x = a[5]
x.next = a[3]
x.next.next = a[1]
etc...
# A dictionary comprehension:
a = {num: Node(num) for num in range(1, 8)}
```
a now looks like:
{1: Node(data=1, next_node=None),
2: Node(data=2, next_node=None),
3: Node(data=3, next_node=None),
4: Node(data=4, next_node=None),
5: Node(data=5, next_node=None),
6: Node(data=6, next_node=None),
7: Node(data=7, next_node=None)}
```
build a linked list:
x = a[5]
x.next = a[3]
x.next.next = a[1]
etc...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment