Professional Documents
Culture Documents
Quizzes Seven Eight
Quizzes Seven Eight
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:
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:
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: