Write a function repfree(s) that takes as input a string s and checks whether any character appears more than once. The function should return True if there are no repetitions and False otherwise.
Answers
Answer:
def repfree(s):
a=set(s)
if len(a)==len(s):
return True
else:
return False
Explanation:
set() method is used to convert any of the iterable to the distinct element and sorted sequence of iterable elements, commonly called Set.
Example : List = [ 3, 4, 1, 4, 5 ]
The list before conversion is : [3, 4, 1, 4, 5]
The list after conversion is : {1, 3, 4, 5}
The function that takes as input a string s and checks whether any character appears more than once and return True if there are no repetitions and False otherwise is :
import collections
def repetitions(s):
final_result = collections.Counter(s)
for i in final_result:
if final_result[i] > 1:
return False
return True