def unique_characters(string_in):
if len(string_in) > 0:
x = set(string_in)
else:
return "Error"
if len(x) == len(string_in):
return True
else:
return False
def unique_characters(string_in):
word_set = set(string_in)
if string_in:
if len(word_set)==len(string_in):
return True
else:
return False
else:
return ‘Error,string is empty’
print(unique_characters(“apple”))
print(unique_characters(“”))
def unique_characters(string_in):
ch = set(string_in)
if(string_in == “”):
return “String is empty”
elif (len(ch) == len(string_in)):
return True
return False
print(unique_characters(“apple”))
def unique_characters(string_in):
""" I used the set() function to create a set of unique characters in the input string.
Then, I compared the length of the set to the length of the input string to check if all characters in the string are
unique
If the lengths are equal, it means that all characters in the string are unique. If not, it means that there are duplicate
characters in the string
The if 'string_in' checks if the 'string_in' parameter is a non-empty string"""
return len(set(string_in)) == len(string_in) if string_in else "error"
print(unique_characters("apple"))
[codebyte]
Beginner here, I got it figured out but yours seems much more simple, I learned the set() function by investigating your solution
[python/codebyte]
def unique_characters(string_in):
chars =
for char in string_in:
chars.append(char)
x = chars.count(char)
if x > 1:
return False
if len(string_in) < 1:
return “Error”
return True
print(unique_characters(“apple”))
I dont even know how to post a bit of code… sorry for the messy response
To preserve code formatting in forum posts, see: [How to] Format code in posts
To post a Codebyte, see: NEW Feature: Codebytes
Usually, properly formatted code (first link) is easier to read and scroll as compared to a Codebyte.
My Solution: