Skip to content

Instantly share code, notes, and snippets.

@plasx
Last active July 27, 2018 20:52
Show Gist options
  • Save plasx/fad4427010674d15344b3dad81214632 to your computer and use it in GitHub Desktop.
Save plasx/fad4427010674d15344b3dad81214632 to your computer and use it in GitHub Desktop.
Daniel's Python 3.7 Cheat sheet

Looping with index

Enumerate

Great for maintaining the index in the loop, as "for i in somelist: " does not maintain the index

items = ['dog','fog', 'jump', 'joma']
for i, item in enumerate(items):
    print(i, item)
0 dog
1 fog
2 jump
3 joma

Enumurate is a great alternative vs the for loop below which doesn't look as pretty as enumerate

for i in range(len(items)):
    print(i, item[i])

Terraform

  tags {
    createddate = "${var.created_date}"
    editeddate = "${timestamp()}"
    createdby = "${var.created_by}"
    environment = "${var.environment}"
  }

Copy

Garbage Collection

ultravalue = 5
insaneultravalue = ultravalue
""" Both will now point to same point in memory"""
insaneultravalue = 20
""" 5 in memory will still be there since ultravalue is referring to it."""
ultravalue = 9
""" 5 in memory is now handled by the garbage collector. Nothing is pointing to it in memory since ultravalue points           to 9 now."""

Azure

dict_a = dict_b = dict_c = {}
dict_c['hello'] = 'goodbye'

print(dict_a)
print(dict_b)
print(dict_c)

Would print:

{'hello': 'goodbye'}
{'hello': 'goodbye'}
{'hello': 'goodbye'}

Terraform

...

Creating A Route Table

Azure

az network route-table create \
--resource-group <Resource Group> \
--location <Location> \
--name <Name>

Terraform

resource "azurerm_route_table" "<resource_name>" {
  name                = <name>
  location            = <location>
  resource_group_name = "${azurerm_resource_group.<resource_name>.name}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment