Y
Y
Yrets1692021-08-24 18:06:11
Python
Yrets169, 2021-08-24 18:06:11

How to output once each character in a string?

this code example displays only those characters that occur once in a string

my_str = "aaaaaaaaaaaaaaaaaaaaaannnnaaaaaaaaaaaahaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa"
for letter in my_str:
  if my_str.count(letter) == 1:
      print(letter)


response received:
h
b

--------------------------------

How to receive response:
a
n
b
h

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-08-24
@Yrets169

print(set(my_str))

M
MegaTochka, 2021-08-24
@MegaTochka

In [28]: s = "abac"
In [29]: for e in set(s):
    ...:     print(e)
    ...:
a
c
b

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question