Python Tips

aka Things I can't seem to remember.

Find the last n elements of a list:

foo = random.sample(range(10, 30), 15)
foo[:-5:-1]

Iterate over a Dictionary

foo = {'a':3, 'b':7, 'cat':13}
for key, value in foo.items():
  print(key, value)

Examine just the first few items of a Dictionary:

list(foo.items())[0:3]

Python (last edited 2020-05-20 21:46:56 by ChrisSeidel)