Search code examples
pythonlistdictionarytext-extraction

Python: Create a list based on elements on text and extracting specific values


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


Solution

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

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