-2

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"]'''
4

1 回答 1

0
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
于 2021-03-04T11:23:56.873 回答