You are on page 1of 3

Quizzes Seven and Eight

Question 1: List Overlap

Task: Write a function common_elements(list1, list2) that takes two lists and returns a list
that contains only the common elements (without duplicates) between the lists given. Ensure the
returned list is sorted in ascending order.

Code:

Output:

Question 2: First and Last

Task: Write a function first_and_last(s) that takes a string s and returns a new string made
of the first 2 and the last 2 characters of the original string. If the string length is less than 2,
return an empty string.
Code:

Output:

Question 3: Increment by Index

Task: Write a function increment_by_index(input_list) that takes a list of integers and


increments each element by its index value. For example, the element at index 0 remains the
same, the element at index 1 is incremented by 1, and so on. Return the modified list.

Code:

Output:
Question 4: Anagram Checker

Task: Write a function are_anagrams(str1, str2) that determines if the two given strings are
anagrams of each other. Ignore case and spaces. Return True if they are anagrams, False
otherwise.

Code:

Output:

You might also like