2023-09-09

find start and end in a series of string and number combination

I have a several points, named by letter plus number. It can be: A1, AA1, A01, AA01...

I have a bunch of them in a list and I want to get a output using "-" to replace intervals.

For example, lst = ['RB11', 'RB12', 'A08', 'A09', 'A10', 'SN13', 'A1', 'A2', 'A3', 'A4'] and I wanna get ['RB11-12','A08-10','SN13,'A1-4']

thank you very much!

I'm thinking about to:

  • split letter and number
  • if repeated letter is found, extract string with that letter
  • get first and last string
  • repeat and create a new list


No comments:

Post a Comment