CS_Program_file_BATCH_2 (2)
CS_Program_file_BATCH_2 (2)
def find_vowels(s):
vowels = "aeiouAEIOU"
return found_vowels
# Example usage
vowel_list = find_vowels(string)
def count_words(sentence):
word_count = count_words(text)
# Function to check if a string starts and ends with the same character def
check_start_end(string):
print("The string does not start and end with the same character.")
def first_non_repeating_char(s):
char_count = {}
char_count[char] = char_count.get(char, 0) + 1
# Find the first character with a count of 1 for char in s:
# Example Usage
List Programs:
6. Find the sum of all even numbers in a list.
def sum_of_evens(lst):
# Example Usage
print(sum_of_evens(numbers)) # Output: 30
def split_list(lst):
# Example Usage
numbers = [1, 2, 3, 4, 5, 6, 7]
def product_of_list(lst):
product = 1 # Initialize product as 1
return product
# Example Usage
numbers = [1, 2, 3, 4, 5]
new_list = [] # Create an empty list to store non-target elements for num in lst:
if num != target: # Keep only elements that are not equal to the target
new_list.append(num)
return new_list
# Example Usage
numbers = [1, 2, 3, 4, 2, 5, 2, 6]
target = 2
def index_of_max(lst):
max_value = lst[0]
for i in range(1, len(lst)): # Start from index 1
max_value = lst[i]
# Example Usage
Tuple Programs:
11.Convert a tuple of strings into a single concatenated string.
def concatenate_tuple_strings(tup):
return result
# Example Usage
def length_of_each_string(tup):
# Defining a tuple
def multiply_tuple_elements(tup):
# Example Usage
numbers = (2, 3, 4, 5)
# Accessing elements
Dictionary Programs:
16.Create a dictionary from two lists: one for keys, another for values.
return dictionary
# Example Usage
print(create_dict(keys, values))
else:
print("Key not found!") # Message if the key is not in the dictionary
# Example Usage
print(student)
return dictionary.pop(key, "Key not found!") # Removes key and returns value or
message
# Example Usage
print(student)
def sum_of_values(dictionary):
# Example Usage
print(sum_of_values(numbers)) # Output: 60
20.Check if a value exists in a dictionary (not the key).
# Example Usage