Anuj Dwivedi
Anuj Dwivedi

Reputation: 7

wants to devide a string in three part

string = "M/s Indian Tobacco Co. pvt. ltd., Godfrey Philips, VST Industries",

'''if starting word is M/s then it will devide it three part as end" ," character '''

like so
'''
[."M/s Indian Tobacco Co. pvt. ltd",
 "Godfrey Philips",
 "VST Industries"]'''

Upvotes: -2

Views: 50

Answers (1)

user9706
user9706

Reputation:

def process(string):
    if string.startswith("M/s"):
      return '\n'.join(f'{i}. {p.strip()}' for i, p in enumerate(string.split(','), start=1))
    else:
      # question does not specify what should happen
      return string

print(process("M/s Indian Tobacco Co. pvt. ltd., Godfrey Philips, VST Industries"));

Gives the output:

1. M/s Indian Tobacco Co. pvt. ltd.
2. Godfrey Philips
3. VST Industries

Upvotes: 0

Related Questions