This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_noise(data_list): | |
"""Removes common noise and unwanted text.""" | |
noise_pattern = r"(\. This is a note\.| ID #\d+|Sent from my mobile\.)" | |
cleaned_data = [re.sub(noise_pattern, "", text) for text in data_list] | |
return cleaned_data | |
print("\n--- Removed Noise ---") | |
cleaned_data = remove_noise(standardized_data) | |
for item in cleaned_data: | |
print(item) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
raw_data = [ | |
"Contact me at user.name@email.com or call me at (123) 456-7890. This is a note.", | |
"Invoice from customer@example.net, phone: 987.654.3210. ID #892", | |
"Sent from my mobile. My email is support@docsallover.io. Call me at 555-123-4567.", | |
"Random text with no useful info.", | |
"Our team can be reached at docsallover@corp.co, or by phone: +1-555-999-8888. " | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Match found! | |
Match found at indices (4, 7) | |
The matched string is: 'cat' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
text = "The cat in the hat." | |
# Pattern to find 'a' followed by any single character, then 't' | |
pattern = 'a.t' | |
# Use re.search() to find the first match | |
match = re.search(pattern, text) | |
# Check if a match was found |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void printNumbers(List<? extends Number> list) { | |
// We can safely read from the list | |
Number num = list.get(0); | |
System.out.println(num); | |
// list.add(10); // COMPILE ERROR: Cannot add to the list | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void addIntegers(List<? super Integer> list) { | |
// We can safely write to the list | |
list.add(10); | |
list.add(20); | |
// Integer num = list.get(0); // COMPILE ERROR: Can't be sure of the type | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void printList(List<?> list) { | |
for (Object element : list) { | |
System.out.println(element); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MaxFinder { | |
// The type T must implement the Comparable interface | |
public static <T extends Comparable<T>> T findMax(T[] array) { | |
if (array == null || array.length == 0) { | |
return null; | |
} | |
T max = array[0]; | |
for (int i = 1; i < array.length; i++) { | |
if (array[i].compareTo(max) > 0) { | |
max = array[i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
public class Util { | |
public static <T> void printList(List<T> list) { | |
for (T element : list) { | |
System.out.println(element); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a Box to hold Strings | |
Box<String> stringBox = new Box<String>(); | |
stringBox.set("Hello Generics!"); | |
// Create a Box to hold Integers | |
Box<Integer> integerBox = new Box<>(); // The compiler infers the type, making it cleaner | |
integerBox.set(123); |