Skip to content

Commit ee2693d

Browse files
committed
Swapcase a input string
1 parent 8d5ae73 commit ee2693d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Remove duplicate lines from Text file/remove_duplicate_lines.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
Replace `sample_file_path.txt` with the location of desired text file to remove duplicate lines(full location path if it is not in the same directory as the code file and only the name if it is in the same directory as the code file).
3+
A new text file "clean_text.txt" will be created in the same directory as the code file with no duplicate lines from `sample_file_path.txt`.
4+
"""
5+
16
content = open('sample_file_path.txt','r').readlines()
27

38
content_set = set(content)

String/sWAPcASE.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Converts and Returns all lowercase letters to uppercase letters and vice versa.
3+
"""
4+
5+
def swap_case(string):
6+
lst= list()
7+
ascii_val = list(map(ord, string))
8+
9+
for value in ascii_val:
10+
if value>64 and value<92:
11+
value = value + 32
12+
elif value>96 and value<124:
13+
value = value - 32
14+
else:
15+
value = value
16+
lst.append(value)
17+
scase = list(map(chr , lst))
18+
19+
res = ""
20+
for c in scase:
21+
res += c
22+
23+
return res
24+
25+
str_input = input()
26+
print(swap_case(str_input))

0 commit comments

Comments
 (0)