development

## Pascal Triangle

def generate(self, numRows): “”” :type numRows: int :rtype: List[List[int]] “”” answer = [] if numRows == 0: return [] row = [1] answer.append(row) for x in range(2, numRows+1): # Prepare the row row = [1]*x # The first and last element on each row is 1, so skip those # indexes. for y in range(1, […]

development

## Why Use Python Ordered Dictionary?

The ordered dictionary offers same time complexity as the standard dict. The implementation is simple: Keep two dictionaries and a doubly-linked list of keys. The DLL maintains order. One dict maps key => DLL node Other dict maps key => value Implementation details https://github.com/python/cpython/blob/3.7/Lib/collections/init.py#L129 Example Problem: Find the first non-repeating char in a string. def […]

development

## Notes on Memory Mapped Files using mmap

Introduction mmap maps a file to a process virtual address space. The file blocks are loaded as needed, in units of the system page size. Each I/O must align with the page size. A block load is handled as a page fault. mmap() can provide a private or shared mapping of a region. mmap() to […]

development

## Check Two Strings are Anagrams?

class Solution(object): def isAnagram(self, s, t): “”” :type s: str :type t: str :rtype: bool “”” # Keep a frequency array frequency = {} for c in s: if c not in frequency: frequency[c] = 1 else: frequency[c] += 1 # Go over the other string for d in t: if d in frequency: frequency[d] […]

development

## Top 5 VSCode Extensions for Vim Lovers

Vim Extensions vscodevim: Vim emulation for Visual Studio Code Better Align (: + = in visual mode) Language Specific Extensions C/C++ C/C++ IntelliSense, debugging, and code browsing. Better C++: better-cpp-syntax Golang Go Microsoft Go Group Imports Go Critic Python Python Microsoft Python Extension Pack Ruby Ruby for Visual Studio Code Rubocop Ruby Solargraph Themes Github […]

development

## Python Cheatsheet – IV

Enumerate a list with index for index, value in enumerate(mylist): print(index, value) Enumerate from a different start index mylist = [5,6,7] for index, value in enumerate(mylist, start= 1): print(index, value) 1 5 2 6 3 7 Dictionary iterate for k, v in d.items(): print(k, v) References https://www.afternerd.com/blog/python-enumerate/ Written with StackEdit.