Interpreting Number Ranges in Python
问题 In a Pylons webapp, I need to take a string such as "<3, 45, 46, 48-51, 77" and create a list of ints (which are actually IDs of objects) to search on. Any suggestions on ways to do this? I'm new to Python, and I haven't found anything out there that helps with this kind of thing. The list would be: [1, 2, 3, 45, 46, 48, 49, 50, 51, 77] 回答1: Use parseIntSet from here I also like the pyparsing implementation in the comments at the end. The parseIntSet has been modified here to handle "<3"-type