forked from manwar/perlweeklychallenge-club
/
ch-1.py
executable file
·49 lines (37 loc) · 1.1 KB
/
ch-1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# make a translation table to switch the case of
# English letters
transTable = str.maketrans(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
)
def greatestEnglishLetter(strVar):
seen = {}
greatest = []
# find the characters that exist as both
# upper and lower case in the string
for c in strVar:
# note that we've seen the character
seen[c] = 1
# swap the case of the character
C = c.translate(transTable)
# if we've seen the swapped case version of the char,
# add the uppercase version to our greatest hits
if C in seen:
greatest.append(c.upper())
# if we found greatest characters,
# return the greater of them
if greatest:
return max(greatest)
# otherwise, return something that
# represents an empty result
return "''"
def solution(strVar):
print(f"Input: '{strVar}'")
print(f"Output: {greatestEnglishLetter(strVar)}")
print('Example 1:')
solution('PeRlwEeKLy')
print('\nExample 2:')
solution('ChaLlenge')
print('\nExample 3:')
solution('The')