Uploaded January 2021 | Updated November 2026, 2 hours ago
In this episode of Python Programming Practice: LeetCode #15 -- 3Sum
Link to the problem here:
leetcode.com/problems/3sum
If you don't know Python, you can learn the basics of Python for data analysis by following along with this YouTube guide I created: youtube.com/playlist?list=PLiC1doDIe9rCYWmH9wIEYEXXaJ4KAi3jc
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: LeetCode #15 -- 3Sum
Link to the problem here:
leetcode.com/problems/3sum
If you don't know Python, you can learn the basics of Python for data analysis by following along with this YouTube guide I created: youtube.com/playlist?list=PLiC1doDIe9rCYWmH9wIEYEXXaJ4KAi3jc
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 Remove Punctuation
↓ Code Available Below! ↓
This video shows how to match and strip punctuation from a text string using the regular expressions package in Python. Text data often contains punctuation that you might want to strip out of text as a preprocessing step before splitting the text into its constituent words for data analysis. The Python regular expressions package makes it easy to match and replace punctuation with empty strings, effectively stripping out all punctuation.
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 @ Vegeta: What does the scouter say about his power level?
Vegeta @ Nappga: Its over (9000!)
Nappa @ Vegeta: [What 9000?] That cant be right... Can it?
# Match and strip punctuation with re.sub()
re.sub(pattern = [^ws],
repl = ,
string = lines)
# Match and strip punctuation and whitespace with re.sub()
re.sub(pattern = W,
repl = ,
string = lines)
* Note you can access some common punctuation characters using:
import string
string.punctuation
** 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 Remove Punctuation](https://i.ytimg.com/vi/hxU3HLX1W1k/mqdefault.jpg)
![How to Access Rows by Name in Pandas (Python)
↓ Code Available Below! ↓
This video shows how to access specific rows of a pandas data frame using the index names of the rows. Data frames dont always have text row names assigned to the columns, but when they do, they can be used to access specific rows instead of using numeric indexing.
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()
# Access a row by by name with .loc
mtcars.loc[Datsun 710]
# Access multiple rows by by name
mtcars.loc[[Datsun 710, Hornet 4 Drive, Mazda RX4]]
# Access multiple rows and specific columns by name
mtcars.loc[[Datsun 710, Hornet 4 Drive, Mazda RX4], [mpg,cyl,hp]]
* 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 Access Rows by Name in Pandas (Python)](https://i.ytimg.com/vi/i04ddbhLDTo/mqdefault.jpg)
![Python Regex: How Find a Substring in a String
↓ Code Available Below! ↓
This video shows how to find and extract substrings within python strings using the regular expressions package. Locating and extracting substrings from larger strings is a common task in text data processing; Python makes it easy to do these sorts of text data processing tasks.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
**Note** if you want to match a specific substring (such as a specific word) and not a regular expression pattern, just pass that word or substring in as the pattern argument.
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.search() to match the first instance of a regex
first_match = re.search(pattern = [0-9]+,
string = lines)
first_match
# Extract the matched string from the match:
first_match.group()
# Extract the index positions of the start and end:
print(first_match.start())
print(first_match.end())
# Use re.finditer() to find all matches:
all_matches = re.finditer(pattern = [0-9]+,
string = lines)
for match in all_matches:
print(match.group(), match.start(), match.end())
# Use re.findall() to get all matches as a list of strings
all_match_list = re.findall(pattern = [0-9]+,
string = lines)
all_match_list
* 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 Find a Substring in a String](https://i.ytimg.com/vi/iESyyogOkY0/mqdefault.jpg)




![How To Use zip() in Python
zip() is a Python built in that lets you combine two or more iterable objects like lists into groups of tuples. zip() is a convenient way of grouping data in multiple lists together in an elementwise fashion.
*Note: Longitude is misspelled in the video! I corrected this in the code below.*
Code used in the video:
# Use zip() to combine iterables like lists into tuples (elementwise)
# Useful for making separate lists into tuples
latitude = [4,5,6,4,6,2,4,5,6]
longitude = [6,3,6,3,4,5,6,8,5]
[*zip(latitude, longitude)]
# Can operate on more than 2 inputs
altitude = [12,41,15,16,15,23,14,51,61]
[*zip(latitude, longitude, altitude)]
# Zip will only continue up to the length of the shortest input
short = [1,2,3,4]
long = [1,2,3,4,5,6,7,8]
[*zip(short, long)]
# If you want to keep all items, use itertools.zip_longest
from itertools import zip_longest
short = [1,2,3,4]
long = [1,2,3,4,5,6,7,8]
[*zip_longest(short, long, fillvalue=None)]
* 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. How To Use zip() in Python](https://i.ytimg.com/vi/kG6nhCinNus/mqdefault.jpg)

![How to Access Columns by Numeric Index in Pandas (Python)
↓ Code Available Below! ↓
This video shows how to access the columns of a pandas data frame using the numeric index using iloc. Using numeric indexes to get columns can make it easier to select multiple columns or large ranges of columns since you dont have to know or type out all of the column names.
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()
# Access a column by numerical index
mtcars.iloc[:, 2]
# Access multiple column by numerical index
mtcars.iloc[:, [2,4,5]]
# Access multiple columns and a subset of rows
mtcars.iloc[[1,5,7], [2,4,5]]
# Access columns with a column subset
mtcars[mtcars.columns[[2,4,5]]]
* 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 Access Columns by Numeric Index in Pandas (Python)](https://i.ytimg.com/vi/lJvG1FpghA4/mqdefault.jpg)