Skip to content
Advertisement

How to select range with input user in list

I want to select a range between elements in a list, but instead of putting, for example, item 7, I put what I’m seeing in elements. The number between ‘document’ and ‘35621’ changes, I need to convert these numbers to a range (I think?)

I don’t really know how to make this.

JavaScript

For example, in my list I have:

JavaScript

I enter in choice input : 456-460

The result would be:

JavaScript

Advertisement

Answer

You can do it like this:

JavaScript

Or alternatively, you can use List Comprehension and do it like this:

JavaScript

Output:

JavaScript

I can see that you’re using Python 2, so the only difference I think is with the print and raw_input. However, since “Python 2.7 will not be maintained past 2020,” I would encourage you to use Python 3 and above.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement