Python practice questions 3.22 output capital English letters

This problem requires writing a program to sequentially output capital English letters that have appeared in a given string, and output each letter only once; if there is no capital English letter, “Not Found” is output.

Input format:

The input is a string ending with a carriage return (less than 80 characters).

Output format:

The capitalized English letters that appear in a line are output in the order of input, and each letter is output only once. If there is no capital English letters, it will output "Not Found".

code show as below:

#!/usr/bin/python
# -*- coding: utf-8 -*-

s = str(input())
m = list(set(list(s)))

#set 去重之后会打乱顺序
m.sort(key = s.index)

value = 0
list = list()

for i in range(0,len(m)):
    if ord(m[i])>64 and ord(m[i])<91:
        list.append(m[i])
        value = value + 1

if value != 0 :
    print("".join(list))
else :
    print("Not Found")

This procedure is relatively simple.

1. Deduplicate the list. The default deduplication will disrupt the order. Use the m.sort (key = s.index) method to sort and sort according to the source list.

2. Make a judgment to create a new list and put capital letters in it.

3. Output capital letters


There is always a book and fitness on the road

Guess you like

Origin www.cnblogs.com/Renqy/p/12723592.html