\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{Aiman Fayyaz} \pdfinfo{ /Title (python.pdf) /Creator (Cheatography) /Author (Aiman Fayyaz) /Subject (Python 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}{A9CCBF} \definecolor{LightBackground}{HTML}{F4F8F7} \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 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Aiman Fayyaz} via \textcolor{DarkBackground}{\uline{cheatography.com/159132/cs/33566/}}} \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}Aiman Fayyaz \\ \uline{cheatography.com/aiman-fayyaz} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 4th June, 2023.\\ Updated 24th August, 2022.\\ 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{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{List Methods}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{append(value)} & adds a value at the end of the list \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} clear() & empties the list \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} copy() & creates a copy of the list \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} count(value) & counts the number of times a value appears in the list \tn % Row Count 7 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{extend(iterable)} & adds the elements of an iterable at the end of the list \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} index(value) & returns the index where the specified value first occurs \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} insert(index, value) & inserts the new value at the specified index \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} pop(index) & removes the element at the specified index \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} pop() & removes the last value from the list \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{remove(value)} & removes the first occurrence of the specified value \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} reverse() & reverses the order of the list \tn % Row Count 23 (+ 2) % Row 11 \SetRowColor{white} sort() & sorts the list values in ascending order(default) \tn % Row Count 25 (+ 2) % Row 12 \SetRowColor{LightBackground} sort(reverse = True) & sorts the list in descending order \tn % Row Count 27 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Random Module}} \tn % Row 0 \SetRowColor{LightBackground} randint(a,b) & returns a random integer between a and b(both inclusive) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{choice(iterable)} & returns a random element from the given iterable \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{choices(iterable)} & returns a list containing a random element from the given iterable \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} random() & returns a random floating point number between 0.0 and 1.0(both exclusive) \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} uniform(a,b) & returns a random floating point number between a and b(both inclusive) \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{shuffle(iterable)} & changes the original sequence of the iterable randomly \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{sample(iterable}, {\bf{k}}=n) & returns a sample of size k(k\textless{}=len) from the iterable \tn % Row Count 21 (+ 3) \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}{Tuple Methods}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{count(element)} & returns the number of times an element occurs in a tuple \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{index(element)} & returns the index of the first occurrence of the specified element \tn % Row Count 5 (+ 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}{Built-in Function}} \tn % Row 0 \SetRowColor{LightBackground} ord(char) & returns the unicode value of a character \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} chr(unicode) & returns the character that represents the unicode \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} bin(n) & converts n into its binary equivalent and returns it as a string \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} oct(n) & converts n into its octal equivalent \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} hex(n) & converts n into its hexadecimal equivalent \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} sum(iterable,start(optional)) & sums all the values of an iterable, start is an optional value to be added to the sum \tn % Row Count 16 (+ 4) % Row 6 \SetRowColor{LightBackground} dir(object) & lists all the attributes of an object \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Dictionary Methods}} \tn % Row 0 \SetRowColor{LightBackground} clear() & removes all the dictionary elements \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} copy() & creates a copy of the dictionary \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} get(key) & gets the value of the specified key \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} keys() & returns a list of all the keys in the dictionary \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} values() & returns a list of all the values in the dictionary \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} items() & returns a list of all elements in the dictionary as tuples of key-value pairs \tn % Row Count 16 (+ 4) % Row 6 \SetRowColor{LightBackground} pop(key) & removes the specified key and its value \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} popitem() & removes the last inserted key and its value \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} dict.fromkeys & creates a dictionary with the specified keys and value(optional), default is none \tn % Row Count 25 (+ 4) % Row 9 \SetRowColor{white} \seqsplit{setdefault(key-value} pair) & returns the value of the specified key, inserts the key if it does not already exist \tn % Row Count 29 (+ 4) % Row 10 \SetRowColor{LightBackground} update(key-value pairs/dictionary) & updates the dictionary with the given values, inserts keys if they do not already exist \tn % Row Count 34 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Set Methods}} \tn % Row 0 \SetRowColor{LightBackground} add(element) & adds an element to the set \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} clear() & empties the entire set \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} copy() & creates a copy of the list \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{x.difference(iterable(s))} & returns a new set containing all the elements of set x that are not present in the other iterables \tn % Row Count 11 (+ 5) % Row 4 \SetRowColor{LightBackground} \seqsplit{x.difference\_update(iterable(s))} & removes all elements from set x that are present in other iterables \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} pop() & removes any element from the set and returns it \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} discard(element) & removes a specified element from the set, does not raise an error if element not found \tn % Row Count 23 (+ 5) % Row 7 \SetRowColor{white} remove(element) & removes a specified element from the set, raises an error if element not found \tn % Row Count 27 (+ 4) % Row 8 \SetRowColor{LightBackground} \seqsplit{intersection(iterable(s))} & returns a new set containing those elements that are common to all iterables \tn % Row Count 31 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Set Methods (cont)}} \tn % Row 9 \SetRowColor{LightBackground} \seqsplit{x.intersection\_update(iterable(s))} & keeps only those elements in set x that are common to all iterables and removes the rest \tn % Row Count 5 (+ 5) % Row 10 \SetRowColor{white} \seqsplit{isdisjoint(iterable(s))} & returns False if the iterables have at least one common element, otherwise True \tn % Row Count 9 (+ 4) % Row 11 \SetRowColor{LightBackground} x.issubset(y) & returns True if set x is a subset of y(any iterable) \tn % Row Count 12 (+ 3) % Row 12 \SetRowColor{white} x.issuperset(y) & returns True if x is a superset of y(any iterable) \tn % Row Count 15 (+ 3) % Row 13 \SetRowColor{LightBackground} \seqsplit{x.union(iterable(s))} & returns a set containing elements present in all the iterables, duplicates are excluded \tn % Row Count 20 (+ 5) % Row 14 \SetRowColor{white} \seqsplit{x.update(iterable(s))} & updates the set x by adding all the elements from the other iterables, duplicates are excluded \tn % Row Count 25 (+ 5) % Row 15 \SetRowColor{LightBackground} \seqsplit{union(iterable(s))} & returns a set which is the union of all the iterables \tn % Row Count 28 (+ 3) % Row 16 \SetRowColor{white} \seqsplit{update(iterable(s))} & updates the set with the union of all iterables \tn % Row Count 31 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}