Check if a string contains all unique characters in Python

Share on facebook
Share on twitter
Share on pinterest

This Python Program will help you check “if a string contains all unique characters”

Python Program To Check If a string contains all unique characters

def isUniqueChars(st):
     if len(st) > 256:
         return False
     char_set = [False] * 128
     for i in range(0, len(st)):
         val = ord(st[i])
         if char_set[val]:
             return False
          char_set[val] = True
      return True
  # driver code
 st = "xyzd"
 print(isUniqueChars(st))

OutPut:

False

Note: Please change the value of st. i.e st= “abcd” and the Output will be “True”.

Subscribe to our Newsletter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Share this post with your friends

Share on facebook
Share on google
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *