1my_string = 'Names: Romeo, Juliet'
2
3# split the string at ':'
4step_0 = my_string.split(':')
5
6# get the first slice of the list
7step_1 = step_0[1]
8
9# split the string at ','
10step_2 = step_1.split(',')
11
12# strip leading and trailing edge spaces of each item of the list
13step_3 = [name.strip() for name in step_2]
14
15# do all the above operations in one go
16one_go = [name.strip() for name in my_string.split(':')[1].split(',')]
17
18for idx, item in enumerate([step_0, step_1, step_2, step_3]):
19 print("Step {}: {}".format(idx, item))
20
21print("Final result in one go: {}".format(one_go))