**Python** 1. Define a function called filter_duplicates() that takes a list and
ID: 3669613 • Letter: #
Question
**Python**
1. Define a function called filter_duplicates() that takes a list and returns a copy of the list with all duplicate values removed. I don't care what order the results come in. For example, filter_duplicates( ["a", "b", "a", "c", "c", "c"] ) should return either ["a", "b", "c"] or ["b", "a", "c"].
2. Write a function called is_anagram() that takes two strings and returns True if the strings are anagrams of each other. The function should not be case-sensitive. Sois_anagram("Listen","Silent") should return True, andis_anagram("foobar","baffor") should return False.
Hint : Make sure you understand what an anagram is before starting this problem. All of the letters in the first word must be used in the second word, and they must be used the same number of times. So "spats" and "past" are not anagrams. And it has to go both ways, so "stat" and "tasty" are not anagrams. There are lots of ways of solving this problem, and you can use whatever method you like. But one good method involves using the string method .count().
3. Write a function called anagrams_in() that takes a string and a list of strings and returns a list of strings from the list that are anagrams of the given string. So anagrams_in("stop", ["tots", "post", "pop", "tops"]) would return ["post","tops"] and So anagrams_in("foobar",["one","two","three","four"]) would return []. Your function should use the is_anagram() function you just wrote.
Explanation / Answer
Multiple Questions : Answering 1st
def filter_duplicates(list1):
list2 = []
for i in list1 :
if i not in list2 :
list2.append(i)
return list2
lista = ["a", "b", "a", "c", "c", "c"]
print filter_duplicates(lista)
-------------------
output :
['a', 'b', 'c']
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.