def linq6(): numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] nums_plus_one = (n + 1 for n in numbers) print("Numbers + 1:") shared.printN(nums_plus_one)
def linq26(): numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] all_but_first3_numbers = dropwhile(lambda n: n % 3 != 0, numbers) print("All elements starting from first element divisible by 3:") shared.printN(all_but_first3_numbers)
def linq32(): doubles = [1.7, 2.3, 1.9, 4.1, 2.9] sorted_doubles = sorted(doubles, reverse=True) print("The doubles from highest to lowest:") shared.printN(sorted_doubles)
def linq57(): numbers = [None, 1.0, "two", 3, "four", 5, "six", 7.0] floats = (n for n in numbers if isinstance(n, float)) print("Numbers stored as floats:") shared.printN(floats)
def linq24(): numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] first_numbers_less_than6 = takewhile(lambda x: x < 6, numbers) print("First numbers less than 6:") shared.printN(first_numbers_less_than6)
def linq46(): factors_of300 = [2, 2, 3, 5, 5] unique_factors = set(factors_of300) print("Prime factors of 300:") shared.printN(unique_factors)
def linq20(): numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] first3_numbers = numbers[:3] print("First 3 numbers:") shared.printN(first3_numbers)
def linq1(): numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] low_nums = (x for x in numbers if x < 5) print("Numbers < 5:") shared.printN(low_nums)
def linq48(): numbers_a = [0, 2, 4, 5, 6, 8, 9] numbers_b = [1, 3, 5, 7, 8] unique_numbers = set(numbers_a + numbers_b) print("Unique numbers from both arrays:") shared.printN(unique_numbers)
def linq50(): numbers_a = [0, 2, 4, 5, 6, 8, 9] numbers_b = [1, 3, 5, 7, 8] common_numbers = set(numbers_a).intersection((set(numbers_b))) print("Common numbers shared by both arrays:") shared.printN(common_numbers)
def linq94(): numbers_a = [0, 2, 4, 5, 6, 8, 9] numbers_b = [1, 3, 5, 7, 8] all_numbers = numbers_a + numbers_b print("All numbers from both arrays:") shared.printN(all_numbers)
def linq52(): numbers_a = [0, 2, 4, 5, 6, 8, 9] numbers_b = [1, 3, 5, 7, 8] a_only_numbers = set(numbers_a).difference((set(numbers_b))) print("Numbers in first array but not second array:") shared.printN(a_only_numbers)
def linq55(): words = ["cherry", "apple", "blueberry"] sorted_words = sorted(words) word_list = list(sorted_words) print("The sorted word list:") shared.printN(word_list)
def linq27(): numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] index = 0 def digit_greater_equal_to_index(digit): nonlocal index result = digit >= index index += 1 return result later_numbers = dropwhile(digit_greater_equal_to_index, numbers) print("All elements starting from first element less than its position:") shared.printN(later_numbers)
def linq25(): numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] index = 0 def digit_greater_equal_to_index(digit): nonlocal index result = digit >= index index += 1 return result first_small_numbers = takewhile(digit_greater_equal_to_index, numbers) print("First numbers not less than their position:") shared.printN(first_small_numbers)
def linq22(): numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0] all_but_first4_numbers = numbers[4:] print("All but first 4 numbers:") shared.printN(all_but_first4_numbers)
def linq66(): numbers = itertools.repeat(7, 10) shared.printN(numbers)