How to find the first non repeated character of a given String?

How to find the first non repeated character of a given String?

https://javarevisited.blogspot.com/2011/06/top-programming-interview-questions.html


CODE:

a = input("Enter a string: ")
b = []
for i in a:
    sum = 0
    for j in a:
        if i == j:
            sum += 1
            if sum > 1:
                break
    if sum == 1:
        b.append(i)
if b:
    print('"{}" is the first non repeated character'.format(b[0]))
else:
    print('None of char is non repeated')
               

           
----

By
PyKar

Comments

Popular posts from this blog

Hardy - Ramanujan Number (Magic Number) Program in Python

FLAMES CODE ON PYTHON

Count Swap for Sorting in Python