Uploaded January 2020 | Updated November 2026, 3 hours ago
In this episode of Python Programming Practice, we tackle LeetCode #14 -- Longest Common Prefix.
Link to the problem here:
leetcode.com/problems/longest-common-prefix
If you don't know Python, you can learn the basics of Python for data analysis using this guide I created on Kaggle (DataDaft video series forthcoming): kaggle.com/hamelg/python-for-data-analysis-index
Python Programming Practice is a series focused on teaching practical coding skills by solving exercises on popular coding websites. Note that the solutions seen here may not be the most efficient possible.
I am not going to provide the full code in the video description for this series, since copy and pasting solutions is not in the spirit of doing coding exercises. It is intended that the video will help you think about problems, approaches and how to structure solutions so that you are able to code up a working solution yourself. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only
In this episode of Python Programming Practice, we tackle LeetCode #14 -- Longest Common Prefix.
Link to the problem here:
leetcode.com/problems/longest-common-prefix
If you don't know Python, you can learn the basics of Python for data analysis using this guide I created on Kaggle (DataDaft video series forthcoming): kaggle.com/hamelg/python-for-data-analysis-index
Python Programming Practice is a series focused on teaching practical coding skills by solving exercises on popular coding websites. Note that the solutions seen here may not be the most efficient possible.
I am not going to provide the full code in the video description for this series, since copy and pasting solutions is not in the spirit of doing coding exercises. It is intended that the video will help you think about problems, approaches and how to structure solutions so that you are able to code up a working solution yourself. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only
![Python Regex: How To Replace All Substrings In a String
↓ Code Available Below! ↓
This video shows how to replace all substrings that match a given pattern with a different string using the regular expressions package in Python. Text data often contains errors or irregularities that need to be fixed prior to using it for other purposes. Finding and replacing substring within text is a common preprocessing task when working with text. The re.sub() function allows you to replace substrings based on a regex patterns, allowing for efficient replacement of multiple substrings at the same time.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import re
lines = Nappa - What does the scouter say about his power level?
Vegeta - Its over 9000!
Nappa - What 9000? That cant be right. Can it?
# Use re.sub() to find and replace substrings
new_lines = re.sub(pattern = [0-9]+,
repl = 8000,
string = lines)
print(new_lines)
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only Python Regex: How To Replace All Substrings In a String](https://i.ytimg.com/vi/5ofcaxkMv5U/mqdefault.jpg)


![How To Add a Column to a Data Frame in Pandas (Python)
This video shows 3 ways to add new columns to Pandas Data Frames in Python. Adding new columns is a basic data manipulation task that is a common part of the data cleaning and wrangling process.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import pandas as pd
import statsmodels.api as sm #(To access mtcars dataset)
mtcars = sm.datasets.get_rdataset(mtcars, datasets, cache=True).data
mtcars.head()
# Method #1: Direct Column Assignment
mtcars[new_1] = mtcars.mpg > 20
mtcars.head()
# Method #2: Use .insert()
mtcars.insert(2, # Where to insert
new_2, # Name of new column
mtcars.mpg > 25) # What to insert
mtcars.head()
# Method #3: Use .assign()
mtcars = mtcars.assign(new_3 = mtcars.mpg > 15, # New column
new_4 = mtcars.mpg > 30) # Another new column
mtcars.head()
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only How To Add a Column to a Data Frame in Pandas (Python)](https://i.ytimg.com/vi/6WmNmAdX5wU/mqdefault.jpg)


![How To Generate Random Numbers in R
This video shows how to reverse vectors, strings and data frames by both columns and rows in R.
Code used in this clip:
# Initialize random number generator
set.seed(12)
# Generate data uniformly within a given range
runif(100, min = 0, max = 10)
# Generate normally distributed data
random_normal <- rnorm(10000, mean = 10, sd = 1)
plot(density(random_normal))
# Generate data by sampling from a vector
die <- c(1,2,3,4,5,6)
# Simulate rolling tow dice and adding the result
two_dice <- sample(die, size = 10000, replace = TRUE) +
sample(die, size = 10000, replace = TRUE)
table(two_dice)
# Sample rows from a data frame
data <- mtcars
index <- sample(1:nrow(data),
size = 10,
replace = FALSE)
data[index,]
Code Clips are basic code explanations in 3 minutes or less. They are intended to be short reference guides that provide quick breakdowns and copy/paste access to code needed to accomplish common data science tasks. Think Stack Overflow with a video explanation.
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! For R that means I may use = for assignment and the special Unicode large < and > symbols in place of the standard sized ones for dplyr pipes and comparisons. These special symbols should work as expected for R code on Windows, but may need to be replaced with standard greater than and less than symbols for other operating systems. How To Generate Random Numbers in R](https://i.ytimg.com/vi/8UyfDajCt4U/mqdefault.jpg)



