Home > Back-end >  Python: Create a list based on elements on text and extracting specific values
Python: Create a list based on elements on text and extracting specific values

Time:02-07

I have the following text:

mytext = '2/3/4/5/6/'

In python, I need to create a list or a dictionary with values on this text, extracting the number between "/", but excluding the last one.

The final result should be something like:

myresult = ['2', '3', '4', '5']

Thank you in advance

CodePudding user response:

mytext.split('/')[:-2]

This should work to create a list for the given format.

  •  Tags:  
  • Related