Interview Question code
Interview Question code
my_list = [1, 2.5, True, 'hello', None] find the largest number using python
list2 = [2.5, 3, 5, 6, 2]
Method 1:
unique_list1 = []
unique_list2 = []
list2 = [2.5, 3, 5, 6, 2]
# Combine both lists, convert to a set to remove duplicates, then back to lists
unique_combined_list = list(set(combined_list))
input_string = "programming"
result = ""
seen = set()
result += char
seen.add(char)
print(result)
count the character in a string and store in key value pair
input_string = "programming"
char_count = {}
if char in char_count:
char_count[char] += 1
else:
char_count[char] = 1
print(char_count)
input_string = "programming"
# Define vowels
vowels = "aeiouAEIOU"
result = ""
result += char
print(result)
input_string = "programming"
# Define vowels
vowels = "aeiouAEIOU"
# Replace each vowel with '*'
print(input_string)
1. Union (| or union())
2. Intersection (& or intersection())
Summary on sets:
A = {1, 2, 3}
B = {3, 4, 5}
# Union
print(A | B) # {1, 2, 3, 4, 5}
# Intersection
# Difference
print(A - B) # {1, 2}
# Symmetric Difference
print(A ^ B) # {1, 2, 4, 5}
# Subset
# Proper Subset
# Cartesian Product
import itertools
print(set(itertools.product(A, B))) # {(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 3), (3, 4), (3, 5)}
U = {1, 2, 3, 4, 5}
print(U - A) # {4, 5}