-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathprog4_Extract_Name.py
More file actions
38 lines (25 loc) · 915 Bytes
/
prog4_Extract_Name.py
File metadata and controls
38 lines (25 loc) · 915 Bytes
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
# Extract First Name
def firstname(name):
try:
f_name = (name).split()[0]
return print("First Name = ", f_name)
except Exception as e:
print(e)
def middlename(name):
m_name = (name).split()[1]
return print("Middle Name = ", m_name)
def lastname(name):
l_name = (name).split()[-1]
return print("Last Name = ", l_name)
# name = input("Enter your name : ")
# print(firstname(name), middlename(name), lastname(name))
# ----------- Query -1 -----------------------------------------------
my_string = 'thisIsAGoodBoy'
# pos = [i for i, e in enumerate(my_string+'A') if e.isupper()]
# parts = [my_string[pos[j]:pos[j+1]] for j in range(len(pos)-1)]
# print(pos)
# print(parts)
# ----------- Query -2 -----------------------------------------------
import re
output = re.findall('[a-zA-Z][^A-Z]*', my_string)
print(output)