One Day at a Time

A site for solving the world's problems

Python Snippets

A collection of cool Python tricks that I like.

Access a dictionary value within a list of dictionaries:

listName[0][key]

Modify a list without explicit pointers using a function in a separate file:

from functDef import *
newList = []
myFunc(newList, 0, 10)
print newList

External function:

def myFunct(listIn, start, end):
    for g in range(start, end + 1):
        listIn.append(g)

Output

bash$: python listThing.py
bash$: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Next Post

Previous Post

© 2024 One Day at a Time

Theme by Anders Norén