string = "M/s Indian Tobacco Co. pvt. ltd., Godfrey Philips, VST Industries",
'''如果起始词是M/s,则将它分成三部分作为结尾","字符'''
like so
'''
[."M/s Indian Tobacco Co. pvt. ltd",
"Godfrey Philips",
"VST Industries"]'''
string = "M/s Indian Tobacco Co. pvt. ltd., Godfrey Philips, VST Industries",
'''如果起始词是M/s,则将它分成三部分作为结尾","字符'''
like so
'''
[."M/s Indian Tobacco Co. pvt. ltd",
"Godfrey Philips",
"VST Industries"]'''
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"));
给出输出:
1. M/s Indian Tobacco Co. pvt. ltd.
2. Godfrey Philips
3. VST Industries