Python Tricks Flashcards
1
Q
Generating Alphabet mapped to idx
A
alpha_map = { chr( i + 65 ) : i+1 for i in range(26)}
2
Q
Priority Queues or Heap Queue
A
heapq.xxxx
3
Q
Creating a counter or dictionary with frequency
A
c = counter(list)
c = {} for item in list: if item not in list: c[item] = 0 c[item] += 1
4
Q
Creating a dictionary with list that last occurrence
A
indexDict = {item : idx for idx, item in enumerate(list)}