Python Challenge - Unique Characters in a String

def unique_characters(string_in): length = len(string_in) unique = len(set(string_in)) if length == 0: print('error') elif length == unique: return True else: return False print(unique_characters("apple"))
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"))
1 Like
def unique_characters(string_in): print(f'The Boolean value of "{string_in} word has only unique characters" is: \n') for idx in range(len(string_in)): for target_value in string_in[idx+1:]: if string_in[idx] == target_value: return False if string_in: return True #Function call string_in = unique_characters('apple') print(string_in)

[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.

def unique_characters(string_in): if(string_in == ""): return "There is an error" while len(string_in) > 1: first = string_in[0] string_in = string_in[1:] if (first in string_in): return False return True

My Solution:

def unique_characters(string_in): if string_in=="": return "Error" else: ans=True for ch in string_in: if string_in.count(ch)>1: ans=False break return ans print(unique_characters("apple"))