Python Tricks Flashcards

1
Q

Generating Alphabet mapped to idx

A

alpha_map = { chr( i + 65 ) : i+1 for i in range(26)}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Priority Queues or Heap Queue

A

heapq.xxxx

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Creating a dictionary with list that last occurrence

A

indexDict = {item : idx for idx, item in enumerate(list)}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly