word_list = ["cat", "dog", "rabbit"]
letter_list = [ ]
for a_word in word_list:
for a_letter in a_word:
letter_list.append(a_letter)
print(letter_list)
How do I get the output value without duplication?
python
word_list = ["cat", "dog", "rabbit"]
letter_set = set()
for a_word in word_list:
for a_letter in a_word:
letter_set.add(a_letter)
print(letter_set)
Why don't you try set?
word_list = ["cat", "dog", "rabbit"]
letter_list = []
for a_word in word_list:
for a_letter in a_word:
if a_letter not in letter_list:
letter_list.append(a_letter)
print(letter_list)
© 2024 OneMinuteCode. All rights reserved.