\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{kush9220} \pdfinfo{ /Title (python-dev.pdf) /Creator (Cheatography) /Author (kush9220) /Subject (Python-Dev 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-Dev Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{kush9220} via \textcolor{DarkBackground}{\uline{cheatography.com/214676/cs/46754/}}} \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}kush9220 \\ \uline{cheatography.com/kush9220} \\ \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 16th July, 2025.\\ 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*}{2} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Random module}} \tn % Row 0 \SetRowColor{LightBackground} random.random() & random float between 0.0 and 1.0 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} random.uniform(a, b) & random float between a and b \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} random.randint(a, b) & random integer between a and b \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} random.randrange(0, 10, 2) & random number from {[}0, 2, 4, 6, 8, 10{]} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{random.choice(list)} & random element from a list \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{random.choices(list}, weights=None, k=2) & k no. of random elements from a list with replacement, weights is a list that specifies the probability of choosing a specific element \tn % Row Count 17 (+ 7) % Row 6 \SetRowColor{LightBackground} random.sample(list, k=2) & k no. of unique elements(no replacement) \tn % Row Count 19 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{random.shuffle(list)} & shuffles a list \tn % Row Count 21 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{random.seed(a=None)} & use this to get the same result every time \tn % Row Count 24 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Types of errors}} \tn % Row 0 \SetRowColor{LightBackground} NameError & Doesn't recognize the name you are using \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} TypeError & When you try to combine or manipulate data in a way python doesn't allow \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} IndexError & The index doesn't exist \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} KeyError & When you try to access a value in a dictionary using a key that doesn't exist \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} ZeroDivisionError & When you divide a number by 0 \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} ValueError & Function recieves a correct type but invalid value \tn % Row Count 17 (+ 3) % Row 6 \SetRowColor{LightBackground} AttributeError & Invalid attribute or method for an object \tn % Row Count 19 (+ 2) % Row 7 \SetRowColor{white} ImportError / \seqsplit{ModuleNotFoundError} & Failed to import a module \tn % Row Count 21 (+ 2) % Row 8 \SetRowColor{LightBackground} FileNotFoundError & File does not exist when trying to open it \tn % Row Count 23 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pandas module}} \tn % Row 0 \SetRowColor{LightBackground} df = \seqsplit{pd.DataFrame(dictionary)} & To convert a dictionary into a pandas dataframe \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} df = \seqsplit{pd.read\_csv('file.csv')} & To convert a csv file into a dataframe \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} df = \seqsplit{pd.read\_excel('file.xlsx')} & To convert an excel file into a dataframe \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} df = \seqsplit{pd.read\_json('file.json')} & To convert a json file into a dataframe \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{df.to\_csv('output.csv'}, index=False) & Convert a dataframe into a csv file \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{df.to\_excel('output.excel')} & Convert a dataframe into an excel file \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} df.head(k) & First k rows, leave empty for five \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} df.tail(k) & Last k rows, leave empty for five \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} df.info() & Data types and non-null values \tn % Row Count 20 (+ 2) % Row 9 \SetRowColor{white} df.describe() & Summary statistics \tn % Row Count 21 (+ 1) % Row 10 \SetRowColor{LightBackground} df.shape & No. of rows and columns \tn % Row Count 23 (+ 2) % Row 11 \SetRowColor{white} df.columns & Column names \tn % Row Count 24 (+ 1) % Row 12 \SetRowColor{LightBackground} df.dtypes & Data types \tn % Row Count 25 (+ 1) % Row 13 \SetRowColor{white} df{[}'col'{]} & A specified column \tn % Row Count 26 (+ 1) % Row 14 \SetRowColor{LightBackground} df.iloc{[}k, l{]} & A specified cell by index, leave l empty for an entire row \tn % Row Count 29 (+ 3) % Row 15 \SetRowColor{white} df.loc{[}k, 'col'{]} & A specified cell by index, 'col' is column name \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pandas module (cont)}} \tn % Row 16 \SetRowColor{LightBackground} df{[}0:5{]} & Slicing rows \tn % Row Count 1 (+ 1) % Row 17 \SetRowColor{white} df{[}df{[}'col'{]} \textgreater{} 25{]} & Filter data by condition \tn % Row Count 3 (+ 2) % Row 18 \SetRowColor{LightBackground} df{[}df{[}'col'{]} \textgreater{} 25 \& (df{[}'Age'{]} \textless{} 40){]} & Filter data by multiple conditions \tn % Row Count 5 (+ 2) % Row 19 \SetRowColor{white} df{[}df{[}'Name'{]}.isin({[}'Alice'{]}){]} & Filter by values \tn % Row Count 7 (+ 2) % Row 20 \SetRowColor{LightBackground} df.rename(columns=\{'old': 'new'\}) & Renaming a column \tn % Row Count 9 (+ 2) % Row 21 \SetRowColor{white} df.drop(columns={[}'Col1', 'Col2'{]}) & Dropping columns \tn % Row Count 11 (+ 2) % Row 22 \SetRowColor{LightBackground} df.drop(index={[}0, 1{]}) & Dropping rows \tn % Row Count 13 (+ 2) % Row 23 \SetRowColor{white} df{[}col{]}.sum() & Sum of values in col \tn % Row Count 14 (+ 1) % Row 24 \SetRowColor{LightBackground} df{[}col{]}.mean() & Mean of values in col \tn % Row Count 16 (+ 2) % Row 25 \SetRowColor{white} df{[}col{]}.value\_counts() & Number of values in col \tn % Row Count 18 (+ 2) % Row 26 \SetRowColor{LightBackground} \seqsplit{df.groupby(col).mean()} & Grouped stats \tn % Row Count 20 (+ 2) % Row 27 \SetRowColor{white} df.isnull() & Returns null values of boolean dataframes \tn % Row Count 23 (+ 3) % Row 28 \SetRowColor{LightBackground} df.isnull().sum() & No. of null values \tn % Row Count 24 (+ 1) % Row 29 \SetRowColor{white} df.dropna() & Drop the row with null values \tn % Row Count 26 (+ 2) % Row 30 \SetRowColor{LightBackground} df.fillna(k) & Fill the missing values with value k \tn % Row Count 28 (+ 2) % Row 31 \SetRowColor{white} df{[}'col'{]} = df{[}'col'{]}.str.strip() & Remove whitespace \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pandas module (cont)}} \tn % Row 32 \SetRowColor{LightBackground} df{[}'col'{]} = df{[}'col'{]}.str.lower() & Present data in lowercase \tn % Row Count 2 (+ 2) % Row 33 \SetRowColor{white} df{[}'col'{]} = pd.to\_datetime(df{[}'col'{]}) & Convert to datetime \tn % Row Count 4 (+ 2) % Row 34 \SetRowColor{LightBackground} \seqsplit{df.sort\_values('Age')} & Sort data by age \tn % Row Count 6 (+ 2) % Row 35 \SetRowColor{white} df.sort\_values({[}'Age', 'Name'{]}) & Sort data by multiple values \tn % Row Count 8 (+ 2) % Row 36 \SetRowColor{LightBackground} \seqsplit{df.reset\_index(drop=True)} & Reset index \tn % Row Count 10 (+ 2) % Row 37 \SetRowColor{white} pd.concat({[}df1, df2{]}) & Appending rows \tn % Row Count 12 (+ 2) % Row 38 \SetRowColor{LightBackground} pd.merge(df1, df2, on='ID') & Joining data by column value \tn % Row Count 14 (+ 2) % Row 39 \SetRowColor{white} pd.merge(df1, df2, how='left', on='ID') & Left joining data by column value \tn % Row Count 16 (+ 2) % Row 40 \SetRowColor{LightBackground} \seqsplit{df.pivot\_table(index='Gender'}, values='Age', aggfunc='mean') & Create a pivot table with mean of the values categorized by index \tn % Row Count 20 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Matplotlib module}} \tn % Row 0 \SetRowColor{LightBackground} plt.plot(x, y, color='red', linestyle='-{}-', marker='o', label='line 1') & Line plot with color red, dashed lines, o marker labeled as 'line 1' \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} plt.title("Title") & Set title of the chart \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{plt.xlabel("x-axis")} & Label of x-axis \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{plt.ylabel("y-axis")} & Label of y-axis \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} plt.legend() & Show legend \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} plt.grid(True) & Show grid \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} plt.show() & Display the chart \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} \seqsplit{plt.figure(figsize=(6}, 4)) & Set figure size \tn % Row Count 13 (+ 2) % Row 8 \SetRowColor{LightBackground} plt.subplot(2, 1, 1) & 2 rows, 1 column, 1st plot \tn % Row Count 15 (+ 2) % Row 9 \SetRowColor{white} plt.tight\_layout() & Avoid overlap \tn % Row Count 16 (+ 1) % Row 10 \SetRowColor{LightBackground} plt.scatter(x, y) & Scatter plot \tn % Row Count 17 (+ 1) % Row 11 \SetRowColor{white} plt.bar(x, y) & Bar plot \tn % Row Count 18 (+ 1) % Row 12 \SetRowColor{LightBackground} plt.barh(x, y) & Horizontal bar plot \tn % Row Count 19 (+ 1) % Row 13 \SetRowColor{white} plt.hist(list, bins=5) & Histogram plot \tn % Row Count 21 (+ 2) % Row 14 \SetRowColor{LightBackground} plt.pie(data\_list, labels=label\_list, \seqsplit{autopct='\%1.1f\%\%')} & Pie chart plot \tn % Row Count 24 (+ 3) % Row 15 \SetRowColor{white} \seqsplit{plt.style.use('ggplot')} & Set global chart style \tn % Row Count 26 (+ 2) % Row 16 \SetRowColor{LightBackground} plt.style.available & Show all chart styles \tn % Row Count 28 (+ 2) % Row 17 \SetRowColor{white} \seqsplit{plt.savefig('plot.pdf'}, dpi=300) & Save chart as pdf with resolution \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Matplotlib module (cont)}} \tn % Row 18 \SetRowColor{LightBackground} \seqsplit{plt.savefig('plot.png')} & Save chart as png \tn % Row Count 2 (+ 2) % Row 19 \SetRowColor{white} plt.text(2, 20, "Sample Text") & Add sample text to x=2, y=20 \tn % Row Count 4 (+ 2) % Row 20 \SetRowColor{LightBackground} \seqsplit{plt.annotate("Important"}, xy=(2, 20), xytext=(3, 25), \seqsplit{arrowprops=dict(facecolor='black'))} & For annotating \tn % Row Count 10 (+ 6) % Row 21 \SetRowColor{white} plt.xscale('log') & Logarithmic x-axis \tn % Row Count 11 (+ 1) % Row 22 \SetRowColor{LightBackground} plt.yscale('log') & Logarithmic y-axis \tn % Row Count 12 (+ 1) % Row 23 \SetRowColor{white} plt.xlim(0, 5) & X-axis limits \tn % Row Count 13 (+ 1) % Row 24 \SetRowColor{LightBackground} plt.ylim(0, 5) & Y-axis limits \tn % Row Count 14 (+ 1) % Row 25 \SetRowColor{white} plt.xticks({[}1, 2, 3{]}) & Custom ticks in x-axis \tn % Row Count 16 (+ 2) % Row 26 \SetRowColor{LightBackground} plt.yticks({[}1, 2, 3{]}) & Custom ticks in y-axis \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Plotly module}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{import plotly.graph\_objects as go} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{import plotly.express as px} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} df = px.data.gapminder() & Returning a Gapminder dataset as a pandas dataframe \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} px.line(df{[}df{[}'country'{]} == 'India'{]}, x='year', y='gdpPercap', title='GDP over time') & Line plot country dataframe, x=year, y=gdppercap and title is GDP over time \tn % Row Count 10 (+ 5) % Row 4 \SetRowColor{LightBackground} px.bar(x={[}'A', 'B'{]}, y={[}10, 20{]}, title='Bar Plot') & Bar plot \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} px.scatter(df, x='gdpPercap', y='lifeExp', color='continent', title='GDP vs Life Expectancy') & Scatter plot \tn % Row Count 18 (+ 5) % Row 6 \SetRowColor{LightBackground} px.scatter(df, x='gdpPercap', y='lifeExp', size='pop', color='continent', \seqsplit{hover\_name='country'}, log\_x=True) & Bubble sort \tn % Row Count 24 (+ 6) % Row 7 \SetRowColor{white} px.choropleth(df{[}df{[}'year'{]}==2007{]}, \seqsplit{locations="iso\_alpha"}, color="lifeExp", \seqsplit{hover\_name="country")} & Map plot (Choropleth) \tn % Row Count 29 (+ 5) % Row 8 \SetRowColor{LightBackground} \seqsplit{fig.update\_layout(title='New} Title', xaxis\_title='X Axis', yaxis\_title='Y Axis', \seqsplit{template='plotly\_dark')} & To customize layout \tn % Row Count 35 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Plotly module (cont)}} \tn % Row 9 \SetRowColor{LightBackground} fig.add\_trace(go.Scatter(x={[}1, 2, 3{]}, y={[}4, 5, 6{]}, \seqsplit{mode='lines+markers'}, name='Line')) & Line plot \tn % Row Count 5 (+ 5) % Row 10 \SetRowColor{white} fig = go.Figure(go.Bar(x={[}'A', 'B'{]}, y={[}10, 15{]})) & Bar plot \tn % Row Count 8 (+ 3) % Row 11 \SetRowColor{LightBackground} go.Figure(go.Pie(labels={[}'A', 'B'{]}, values={[}30, 70{]})) & Pie plot \tn % Row Count 11 (+ 3) % Row 12 \SetRowColor{white} \seqsplit{fig.write\_html("plot.html")} & Save as html file \tn % Row Count 13 (+ 2) % Row 13 \SetRowColor{LightBackground} \seqsplit{fig.write\_image("plot.png")} & Save as image file \tn % Row Count 15 (+ 2) % Row 14 \SetRowColor{white} \seqsplit{fig.update\_layout(hovermode='x} unified') & Tooltip follows x \tn % Row Count 17 (+ 2) % Row 15 \SetRowColor{LightBackground} \seqsplit{fig.update\_traces(marker=dict(size=10))} & Change marker size \tn % Row Count 19 (+ 2) % Row 16 \SetRowColor{white} \seqsplit{fig.update\_layout(dragmode='zoom')} & Default zoom tool \tn % Row Count 21 (+ 2) % Row 17 \SetRowColor{LightBackground} \seqsplit{fig.update\_layout(template='plotly\_dark')} & Update the style of theme \tn % Row Count 24 (+ 3) % Row 18 \SetRowColor{white} \seqsplit{px.scatter\_geo(px.data.gapminder().query("year==2007")}, \seqsplit{locations="iso\_alpha"}, color="continent", size="pop") & Map visualizations \tn % Row Count 31 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Plotly module (cont)}} \tn % Row 19 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{from plotly.subplots import make\_subplots} \tn % Row Count 1 (+ 1) % Row 20 \SetRowColor{white} fig = \seqsplit{make\_subplots(rows=1}, cols=2) & To set subplots \tn % Row Count 3 (+ 2) % Row 21 \SetRowColor{LightBackground} fig.add\_trace(go.Scatter(x={[}1, 2{]}, y={[}3, 4{]}), row=1, col=1) & add trace in a subplot \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.24 cm} x{3.76 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Glob module}} \tn % Row 0 \SetRowColor{LightBackground} glob.glob('*.txt') & All .txt files in current directory \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} glob.glob('{\emph{*/}}.txt', recursive=True) & Match files in subdirectories \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} glob.glob('*.txt', recursive=False, \seqsplit{include\_hidden=False)} & Sort matched files \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Glob module works best when worked with Regex expressions} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.6 cm} x{6.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Types of data structures}} \tn % Row 0 \SetRowColor{LightBackground} Lists & Indexing, Slicing, Extending and Mutability, syntax: my\_list = {[}1, 1.21, "hello", True{]} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Tuples & Indexing, Slicing and Immutable, syntax: my\_tuple = (1, 10, "hello") \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Sets & Unordered nature, Key operations are add(), remove(), union(), intersection(), difference(), syntax: my\_set = \{1, 2, 3, 3\} \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} \seqsplit{Dictionary} & Accessing values by key, Mutability and flexibility, common operations are get(), items(), keys(), values(), update(), syntax: my\_dict = \{"name": "Alice", "age": 30, "city": "New York"\} \tn % Row Count 16 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pytest module}} \tn % Row 0 \SetRowColor{LightBackground} assert result == k & checks if the result variable is the same as the variable assigned as k \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} @pytest.fixture & to define a fixture to use as a reusable piece of code to use before or after a test \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} \seqsplit{@pytest.mark.parametrize("a}, b, result", {[}(1, 2, 3), (4, 5, 9){]}) & checks the result variable with a and b by performing numerous tests based on the data we give \tn % Row Count 14 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{@pytest.mark.skip(reason="Not} implemented yet") & skip a particular test \tn % Row Count 17 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{@pytest.mark.skipif(condition}, reason="...") & skip the test given the condition \tn % Row Count 20 (+ 3) % Row 5 \SetRowColor{white} @pytest.mark.xfail & If you are expecting a test to fail \tn % Row Count 22 (+ 2) % Row 6 \SetRowColor{LightBackground} pytest.raises() & to raise a specific type of error \tn % Row Count 24 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Numpy module}} \tn % Row 0 \SetRowColor{LightBackground} np.array({[}1, 2, 3{]}, {[}4, 5, 6{]}) & Creating a 2D array \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} np.zeros((3, 3)) & 3x3 array of zeros \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} np.ones((3, 3)) & 3x3 array of ones \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} np.full((2, 2), 7) & 2x2 array of sevens \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} np.eye(3) & Identity matrix 3x3 \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} np.arrange(0, 10, 2) & An array of this: {[}0, 2, 4, 6, 8{]} \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} np.linspace(0, 1, 5) & 5 values from 0 to 1 \tn % Row Count 11 (+ 2) % Row 7 \SetRowColor{white} arr.shape & Dimensions of the array \tn % Row Count 13 (+ 2) % Row 8 \SetRowColor{LightBackground} arr.ndim & No. of dimensions \tn % Row Count 14 (+ 1) % Row 9 \SetRowColor{white} arr.size & Total no. of elements \tn % Row Count 15 (+ 1) % Row 10 \SetRowColor{LightBackground} arr.dtype & Data type \tn % Row Count 16 (+ 1) % Row 11 \SetRowColor{white} arr.reshape((2, 3)) & Reshape an array to 2x3 \tn % Row Count 18 (+ 2) % Row 12 \SetRowColor{LightBackground} arr.ravel() & Compress an array to 1D \tn % Row Count 20 (+ 2) % Row 13 \SetRowColor{white} arr.T & Transpose the array \tn % Row Count 21 (+ 1) % Row 14 \SetRowColor{LightBackground} np.add(a, b) & a + b \tn % Row Count 22 (+ 1) % Row 15 \SetRowColor{white} np.subtract(a, b) & a - b \tn % Row Count 23 (+ 1) % Row 16 \SetRowColor{LightBackground} np.multiply(a, b) & a * b \tn % Row Count 24 (+ 1) % Row 17 \SetRowColor{white} np.divide(a, b) & a / b \tn % Row Count 25 (+ 1) % Row 18 \SetRowColor{LightBackground} np.power(a, 2) & a to the power of 2 \tn % Row Count 26 (+ 1) % Row 19 \SetRowColor{white} np.sqrt(a) & Square root of a \tn % Row Count 27 (+ 1) % Row 20 \SetRowColor{LightBackground} np.exp(a) & Exponential value of a \tn % Row Count 28 (+ 1) % Row 21 \SetRowColor{white} np.log(a) & Natural log of a \tn % Row Count 29 (+ 1) % Row 22 \SetRowColor{LightBackground} np.mean(list) & Mean of the list \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Numpy module (cont)}} \tn % Row 23 \SetRowColor{LightBackground} np.median(list) & Median of the list \tn % Row Count 1 (+ 1) % Row 24 \SetRowColor{white} np.std(list) & Standard deviation of the list \tn % Row Count 3 (+ 2) % Row 25 \SetRowColor{LightBackground} np.sum(list) & Sum of the list \tn % Row Count 4 (+ 1) % Row 26 \SetRowColor{white} np.max(list) & Maximum value in a list \tn % Row Count 6 (+ 2) % Row 27 \SetRowColor{LightBackground} np.min(list) & Minimum value in a list \tn % Row Count 8 (+ 2) % Row 28 \SetRowColor{white} np.argmax(list) & Index of maximum value \tn % Row Count 9 (+ 1) % Row 29 \SetRowColor{LightBackground} np.argmin(list) & Index of minimum value \tn % Row Count 10 (+ 1) % Row 30 \SetRowColor{white} np.concatenate({[}a, b{]}) & Join arrays \tn % Row Count 12 (+ 2) % Row 31 \SetRowColor{LightBackground} np.vstack({[}a, b{]}) & Stack vertically \tn % Row Count 13 (+ 1) % Row 32 \SetRowColor{white} np.hstack({[}a, b{]}) & Stack horizontally \tn % Row Count 14 (+ 1) % Row 33 \SetRowColor{LightBackground} np.split(a, 3) & Split the array into 3 parts \tn % Row Count 16 (+ 2) % Row 34 \SetRowColor{white} np.unique(a) & Unique elements of the array \tn % Row Count 18 (+ 2) % Row 35 \SetRowColor{LightBackground} np.random.rand(2, 2) & a 2x2 array of random elements from 0 to 1 \tn % Row Count 20 (+ 2) % Row 36 \SetRowColor{white} \seqsplit{np.random.randn(2}, 2) & a 2x2 array of random elements, this will be a normal distribution \tn % Row Count 23 (+ 3) % Row 37 \SetRowColor{LightBackground} \seqsplit{np.random.randint(0}, 10, size=5) & a 1D array of 5 random integers from 0 to 10 \tn % Row Count 25 (+ 2) % Row 38 \SetRowColor{white} np.isnan(a) & Check for NaN values \tn % Row Count 26 (+ 1) % Row 39 \SetRowColor{LightBackground} np.isinf(a) & Check for Inf values \tn % Row Count 27 (+ 1) % Row 40 \SetRowColor{white} np.nan\_to\_num(a) & Convert NaN to 0 \tn % Row Count 28 (+ 1) % Row 41 \SetRowColor{LightBackground} np.clip(a, 0, 1) & Limit values between 0 to 1 \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Numpy module (cont)}} \tn % Row 42 \SetRowColor{LightBackground} np.where(a \textgreater{} 0, 1, 0) & Conditional values \tn % Row Count 2 (+ 2) % Row 43 \SetRowColor{white} np.cumsum(a) & Cumulative sum \tn % Row Count 3 (+ 1) % Row 44 \SetRowColor{LightBackground} np.cumprod(a) & Cumulative product \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Bokeh module}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{from bokeh.plotting import figure, show} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{from bokeh.io import output\_file, output\_notebook} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{from bokeh.layouts import column, row} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{output\_file("plot.html")} & Output to html file \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} output\_notebook() & Output to Jupyter notebook \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} p = \seqsplit{figure(title="Simple} Line", x\_axis\_label='x', y\_axis\_label='y') & Label the figure \tn % Row Count 11 (+ 4) % Row 6 \SetRowColor{LightBackground} p.line({[}1, 2, 3{]}, {[}4, 6, 2{]}) & Line plot \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} show(p) & Show the chart \tn % Row Count 14 (+ 1) % Row 8 \SetRowColor{LightBackground} p.circle(x, y, size=10) & Scatter plot \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} p.vbar(x=x, top=y, width=0.5) & Vertical bar plot \tn % Row Count 18 (+ 2) % Row 10 \SetRowColor{LightBackground} p.hbar(x=x, top=y, width=0.5) & Horizontal bar plot \tn % Row Count 20 (+ 2) % Row 11 \SetRowColor{white} p.triangle(x, y, size=12, color="green") & Shape plot, other glyphs available ex: square, diamond etc. \tn % Row Count 23 (+ 3) % Row 12 \SetRowColor{LightBackground} p.title.text = "Custom Title" & Set title \tn % Row Count 25 (+ 2) % Row 13 \SetRowColor{white} p.xaxis.axis\_label = "X Axis" & Label x-axis \tn % Row Count 27 (+ 2) % Row 14 \SetRowColor{LightBackground} p.yaxis.axis\_label = "Y Axis" & Label y-axis \tn % Row Count 29 (+ 2) % Row 15 \SetRowColor{white} \seqsplit{p.background\_fill\_color} = "lightgray" & Set background color \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Bokeh module (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \seqsplit{p.border\_fill\_color} = "whitesmoke" & Set border color \tn % Row Count 2 (+ 2) % Row 17 \SetRowColor{white} \seqsplit{p.outline\_line\_color} = "black" & Set outline line color \tn % Row Count 4 (+ 2) % Row 18 \SetRowColor{LightBackground} p.line(x, y, legend\_label="My Line", line\_width=2) & define legend\_label for legend \tn % Row Count 7 (+ 3) % Row 19 \SetRowColor{white} p.legend.location = "top\_left" & Set interactive legend \tn % Row Count 9 (+ 2) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{p.legend.click\_policy = "hide"} \tn % Row Count 10 (+ 1) % Row 21 \SetRowColor{white} layout = row(p1, p2) & To set layout of a row \tn % Row Count 12 (+ 2) % Row 22 \SetRowColor{LightBackground} layout = column(p1, p2) & To set layout of a column \tn % Row Count 14 (+ 2) % Row 23 \SetRowColor{white} show(layout) & Show layout \tn % Row Count 15 (+ 1) % Row 24 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{from bokeh.models import ColumnDataSource} \tn % Row Count 16 (+ 1) % Row 25 \SetRowColor{white} source = ColumnDataSource(data=\{'x': {[}1, 2, 3{]}, 'y': {[}4, 6, 5{]}\}) & Set a data source \tn % Row Count 20 (+ 4) % Row 26 \SetRowColor{LightBackground} p.circle(x='x', y='y', source=source, size=10) & Plot a circle chart from data source \tn % Row Count 23 (+ 3) % Row 27 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{from bokeh.io.export import export\_png} \tn % Row Count 24 (+ 1) % Row 28 \SetRowColor{LightBackground} export\_png(p, \seqsplit{filename="plot.png")} & Export chart to png file \tn % Row Count 26 (+ 2) % Row 29 \SetRowColor{white} p1.x\_range = p2.x\_range & Link x-axis \tn % Row Count 28 (+ 2) % Row 30 \SetRowColor{LightBackground} p1.y\_range = p2.y\_range & Link y-axis \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Bokeh module (cont)}} \tn % Row 31 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{from bokeh.embed import components} \tn % Row Count 1 (+ 1) % Row 32 \SetRowColor{white} script, div = components(p) & Use in html templates \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Os module}} \tn % Row 0 \SetRowColor{LightBackground} os.getcwd() & Returns the current working directory \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{os.chdir('path/to/directory')} & Changes current working directory \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{os.listdir('path')} & Lists files and folders in the specified path \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{os.mkdir('dirname')} & Creates a single directory \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{os.makedirs('dir/subdir')} & Creates intermediate directories as needed \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{os.rmdir('dirname')} & Removes an empty directory \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{os.removedirs('dir/subdir')} & Removes nested empty directories \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{os.remove('filename')} & Removes a file \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{os.path.exists('path')} & Returns true if path exists \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{os.path.isfile('path')} & True if it's a file \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} \seqsplit{os.path.isdir('path')} & True if it's a directory \tn % Row Count 23 (+ 2) % Row 11 \SetRowColor{white} \seqsplit{os.path.join('folder'}, 'file.txt') & Combines path using the right seperator \tn % Row Count 25 (+ 2) % Row 12 \SetRowColor{LightBackground} \seqsplit{os.path.basename('path/to/file.txt')} & Returns file.txt \tn % Row Count 27 (+ 2) % Row 13 \SetRowColor{white} \seqsplit{os.path.dirname('path/to/file.txt')} & Returns 'path/to' \tn % Row Count 29 (+ 2) % Row 14 \SetRowColor{LightBackground} \seqsplit{os.path.split('path/to/file.txt')} & Returns ('path/to', 'file.txt') \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Os module (cont)}} \tn % Row 15 \SetRowColor{LightBackground} \seqsplit{os.path.abspath('file.txt')} & Returns absolute path to the file \tn % Row Count 2 (+ 2) % Row 16 \SetRowColor{white} \seqsplit{os.environ.get('HOME')} & Retrieves the path to the current user's home directory \tn % Row Count 5 (+ 3) % Row 17 \SetRowColor{LightBackground} os.environ{[}'MY\_VAR'{]} = 'value' & Sets or creates an environment variable within the current environment process \tn % Row Count 9 (+ 4) % Row 18 \SetRowColor{white} os.system('ls') & Executes a shell command \tn % Row Count 11 (+ 2) % Row 19 \SetRowColor{LightBackground} os.getpid() & Current process ID \tn % Row Count 12 (+ 1) % Row 20 \SetRowColor{white} os.getppid() & Current parent process ID \tn % Row Count 14 (+ 2) % Row 21 \SetRowColor{LightBackground} \seqsplit{os.rename('old.txt'}, 'new.txt') & Renaming a file or a directory \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Shutil module}} \tn % Row 0 \SetRowColor{LightBackground} shutil.copy(src, destination) & Copies file to destination \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} shutil.copy2(src, dst) & It's like copying but preserves metadata \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} shutil.copymode(src, dst) & Copies file permissions only \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} shutil.copystat(src, dst) & Copies file's metadata only \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} shutil.copytree(src, dst & Copies entire directory tree \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} shutil.move(src, dst) & Moves or renames a file \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{shutil.rmtree('dir')} & Deletes directory and everything in it \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{shutil.make\_archive(base\_name}, format, root\_dir) & Creates archive in any format \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} \seqsplit{shutil.unpack\_archive(filename}, extract\_dir) & Unpacks the archive \tn % Row Count 20 (+ 3) % Row 9 \SetRowColor{white} \seqsplit{shutil.disk\_usage(path)} & Gets disk usage stats \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Re module}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{re.search(pattern}, string) & Searches for first match everywhere \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{re.match(pattern}, string) & Checks for a match only at the beginning \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{re.fullmatch(pattern}, str) & Matches entire string to pattern \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{re.findall(pattern}, string) & Returns all non-overlapping matches \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{re.finditer(pattern}, string) & Returns iterators yielding match objects \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} re.sub(pat, repl, string) & Replace matches with repl \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{re.split(pattern}, string) & Split string by the matches \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{re.compile(pattern)} & Precompile a pattern for reuse \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Regex Expressions used in Python:} \tn % Row Count 17 (+ 1) % Row 9 \SetRowColor{white} . & Matches any character except newline, use like this: a.b.c to match a1b7c, asbfc, a9bkc etc. \tn % Row Count 21 (+ 4) % Row 10 \SetRowColor{LightBackground} ? & Use after a character to define it occurs 0 or 1 times \tn % Row Count 24 (+ 3) % Row 11 \SetRowColor{white} \textbackslash{} & To define a Regex pattern / Escape character \tn % Row Count 26 (+ 2) % Row 12 \SetRowColor{LightBackground} * & Use after a pattern to define 0 or more repetitions \tn % Row Count 29 (+ 3) % Row 13 \SetRowColor{white} + & Use after a pattern to define 1 or more repetitions \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Re module (cont)}} \tn % Row 14 \SetRowColor{LightBackground} \textasciicircum{} & Use before a pattern to define start of a string \tn % Row Count 3 (+ 3) % Row 15 \SetRowColor{white} \$ & Use after a pattern to define end of string \tn % Row Count 5 (+ 2) % Row 16 \SetRowColor{LightBackground} \{k\} & Use to define k number of repetitions for a pattern \tn % Row Count 8 (+ 3) % Row 17 \SetRowColor{white} \{k, l\} & Use to define between k and l repetitions \tn % Row Count 10 (+ 2) % Row 18 \SetRowColor{LightBackground} {[}{]} & define a list of characters and use if you match from one of them \tn % Row Count 13 (+ 3) % Row 19 \SetRowColor{white} \textbackslash{}d & Specifies digits {[}0-9{]} \tn % Row Count 14 (+ 1) % Row 20 \SetRowColor{LightBackground} \textbackslash{}D & Anything that's not a digit \tn % Row Count 16 (+ 2) % Row 21 \SetRowColor{white} \textbackslash{}w & Any word character {[}a-zA-Z0-9\_{]} \tn % Row Count 18 (+ 2) % Row 22 \SetRowColor{LightBackground} \textbackslash{}W & Anything that is not a word character \tn % Row Count 20 (+ 2) % Row 23 \SetRowColor{white} \textbackslash{}s & Whitespace \textbackslash{} Spacing between two words \tn % Row Count 22 (+ 2) % Row 24 \SetRowColor{LightBackground} \textbackslash{}S & Non-whitespace \tn % Row Count 23 (+ 1) % Row 25 \SetRowColor{white} \textbackslash{}b & Word boundary, used to match whole words only like: \textbackslash{}bcat\textbackslash{}b to match 'cat', 'little cat' and not 'tomocat' or 'catatine' \tn % Row Count 29 (+ 6) % Row 26 \SetRowColor{LightBackground} \textbackslash{}B & Non-word boundary, best used to match a word which has that letter like: \textbackslash{}bun\textbackslash{}b matches 'unmalicious', 'unnasty' and not 'un' or 'we un' \tn % Row Count 35 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}