\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Ptero} \pdfinfo{ /Title (python-coding-interview.pdf) /Creator (Cheatography) /Author (Ptero) /Subject (Python Coding Interview Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Python Coding Interview Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Ptero} via \textcolor{DarkBackground}{\uline{cheatography.com/190551/cs/39752/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Ptero \\ \uline{cheatography.com/ptero} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 10th August, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Type built-in}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{bool}}(x=False)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{bytearray}}(source=b'')\{\{nl\}\}{\bf{bytearray}}(source, encoding, errors)} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{bytes}}(source=b'')\{\{nl\}\}{\bf{bytes}}(source, encoding, errors)} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{complex}}(real=0, imag=0)\{\{nl\}\}{\bf{complex}}(string)} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{dict}}(**kwarg)\{\{nl\}\}{\bf{dict}}(mapping, **kwarg)\{\{nl\}\}{\bf{dict}}(iterable, **kwarg)} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{float}}(x=0.0)} \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{int}}(x=0)\{\{nl\}\}{\bf{int}}(x, base=10)} \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{set}}(iterable)} \tn % Row Count 12 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{str}}(object='')\{\{nl\}\}{\bf{str}}(object=b'', encoding='utf-8', errors='strict')} \tn % Row Count 14 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{tuple}}(iterable)} \tn % Row Count 15 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Built-in math functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{abs}}(x)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{divmod}}(a, b)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{max}}(iterable, *, default, key=None)\{\{nl\}\}{\bf{max}}(arg1, arg2, *args, key=None)} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{min}}(iterable, *, default, key=None)\{\{nl\}\}{\bf{min}}(arg1, arg2, *args, key=None)} \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{pow}}(base, exp, mod=None)} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{round}}(number, ndigits=None)} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{sum}}(iterable, /, start=0)} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{String built-in functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{bin}}(x)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{chr}}(i)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{hex}}(x)} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{oct}}(x)} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{ord}}(c)} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{print}}(*objects, sep=' ', end='\textbackslash{}n', file=None, flush=False)} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Functional programming}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{filter}}(function, iterable)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{map}}(function, iterable, *iterables)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{func = lambda a, b, c : a + b + c} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Other built-in functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{all}}(iterable)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{any}}(iterable)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{enumerate}}(iterable, start=0)} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{sorted}}(iterable, /, *, key=None, reverse=False)} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{zip}}(*iterables, strict=False)} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Misc}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{occurrence} & import collections\{\{nl\}\}d = defaultdict(int)\{\{nl\}\}for w in words:\{\{nl\}\}d{[}w{]} += 1 \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.69218 cm} x{3.28482 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Min Max}} \tn % Row 0 \SetRowColor{LightBackground} min int/float & float('-inf')\{\{nl\}\}// or\{\{nl\}\}-math.inf \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} max int/float & float('inf')\{\{nl\}\}// or\{\{nl\}\}math.inf \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} min & m = min(a, b, c, ...) \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} min in array & m = min(arr) \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} min in dict key & m = min(\{1:4, 2:3\}) \# 1 \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} dict key w/ min value & d = \{1:4, 2:3\}\{\{nl\}\}m = min(d, key = lamba k : d{[}k{]}) \# 2 \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.09034 cm} x{2.88666 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{String}} \tn % Row 0 \SetRowColor{LightBackground} new & s = "str" \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} get & c = s{[}i{]} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} check empty & if not s: \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} length & length = len(s) \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} compare & if s1 == s2: \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} reverse & r = s{[}::-1{]} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} to lower & s = s.{\bf{lower}}() \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} to upper & s = s.{\bf{upper}}() \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} get sub string & sub = s{[}from : to{]} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} check sub string & if sub in s: \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} split & arr = s.{\bf{split}}(sep) \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} join & s = sep.{\bf{join}}(arr) \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{List}} \tn % Row 0 \SetRowColor{LightBackground} new & arr = {[}1, 2, 3{]} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} get & num = arr{[}i{]} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} check empty & if not arr: \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} length & length = len(arr) \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} reverse & r = arr{[}::-1{]} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} get sub array & sub = arr{[}from : to{]} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} fill & arr = {[}i for i in range(5){]} \tn % Row Count 8 (+ 2) % Row 7 \SetRowColor{white} traverse & for num in arr: \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} sort asscending (in-place) & arr.{\bf{sort}}() \tn % Row Count 11 (+ 2) % Row 9 \SetRowColor{white} sort descending (in-place) & arr.{\bf{sort}}(reverse=True) \tn % Row Count 13 (+ 2) % Row 10 \SetRowColor{LightBackground} find index & index = arr.{\bf{index}}(num, start, end) \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Stack}} \tn % Row 0 \SetRowColor{LightBackground} new & stack = {[}{]} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} push & stack.{\bf{append}}(num) \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} pop & popped = stack.{\bf{pop}}() \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} top & top = stack{[}-1{]} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} check empty & if not stack: \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} length & length = len(stack) \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Queue}} \tn % Row 0 \SetRowColor{LightBackground} new & queue = {[}{]} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} push & queue.{\bf{append}}(num) \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} pop & popped = queue.{\bf{pop}}(0) \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} front & front = queue{[}0{]} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} check empty & if not queue: \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} length & length = len(queue) \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.09494 cm} x{3.88206 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Heap}} \tn % Row 0 \SetRowColor{LightBackground} import & import heapq \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} new & heapq = {[}{]} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} heapify & heapq.{\bf{heapify}}(heap) \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} push & heapq.{\bf{heappush}}(heap, item) \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} pop & smallest = heapq.{\bf{heappop}}(heap) \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} push \& pop & smallest = heapq.{\bf{heappushpop}}(heap, item) \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} pop \& push & smallest = heapq.{\bf{heapreplace}}(heap, item) \tn % Row Count 10 (+ 2) % Row 7 \SetRowColor{white} peek & smallest = heap{[}0{]} \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} check empty & if not queue: \tn % Row Count 13 (+ 2) % Row 9 \SetRowColor{white} length & length = len(queue) \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Set}} \tn % Row 0 \SetRowColor{LightBackground} new & s = set() \# for empty set\{\{nl\}\}\# or\{\{nl\}\}s = \{1, 2, 3\} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} add & s.{\bf{add}}(item) \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} add list & s.{\bf{update}}(arr) \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} delete & s.{\bf{remove}}(item) \# throw error\{\{nl\}\}\# or\{\{nl\}\}s.{\bf{discard}}(item) \# no error \tn % Row Count 7 (+ 3) % Row 4 \SetRowColor{LightBackground} clear & s.{\bf{clear}}() \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} check empty & if not s: \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} check in set & if item in s: \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} size & length = len(s) \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} to list & arr = list(s) \tn % Row Count 12 (+ 1) % Row 9 \SetRowColor{white} merge & s = s1 {\bf{|}} s2 \tn % Row Count 13 (+ 1) % Row 10 \SetRowColor{LightBackground} \seqsplit{intersection} & s = s1 {\bf{\&}} s2 \tn % Row Count 14 (+ 1) % Row 11 \SetRowColor{white} difference & s = s1 {\bf{-}} s2 \tn % Row Count 15 (+ 1) % Row 12 \SetRowColor{LightBackground} symetric difference & s = s1 {\bf{\textasciicircum{}}} s2 \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Dict}} \tn % Row 0 \SetRowColor{LightBackground} new & d = \{\} \# for empty dict\{\{nl\}\}\# or\{\{nl\}\}d = \{1:2, 3:4\} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} set & d{[}key{]} = val \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} get & val = d{[}key{]} \# throws error\{\{nl\}\}\# or\{\{nl\}\}val = d.get(key) \# None if not exist \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} delete & val = s.{\bf{pop}}(key)\{\{nl\}\}\# or\{\{nl\}\}{\bf{del}} d{[}key{]} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} delete last & key, val = s.{\bf{popitem}}() \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} clear & {\bf{del}} d \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} check empty & if not d: \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} check key in dict & if key in d.{\bf{keys}}(): \tn % Row Count 13 (+ 2) % Row 8 \SetRowColor{LightBackground} check value in dict & if val in d.{\bf{values}}(): \tn % Row Count 15 (+ 2) % Row 9 \SetRowColor{white} size & length = len(s) \tn % Row Count 16 (+ 1) % Row 10 \SetRowColor{LightBackground} iterate & for key, val in d.items(): \tn % Row Count 17 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.39356 cm} x{3.58344 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Queue (thread safe)}} \tn % Row 0 \SetRowColor{LightBackground} import & from queue import SimpleQueue \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} new & queue = SImpleQueue() \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} push & queue.{\bf{put}}(num) \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} pop & popped = queue.{\bf{get}}() \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} check empty & if queue.{\bf{empty}}(): \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} length & length = queue.{\bf{qsize}}() \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{PriorityQueue (thread safe)}} \tn % Row 0 \SetRowColor{LightBackground} import & from queue import PriorityQueue \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} new & pq = PriorityQueue() \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} push & pq.{\bf{put}}(num) \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} pop & popped = pq.{\bf{get}}() \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} check empty & if pq.{\bf{empty}}(): \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} length & length = pq.{\bf{qsize}}() \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}