Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Richard Lu20,185 Points
Negating numbers that are spread out
Hi, I am having trouble finding out how to find numbers that are spread out. An example would be trying to find the numbers 1, 5, 7, 9. The code below finds all the numbers from 5-7, but what If i don't want 6? How would I go about it?
import re string = '1234567890' good_numbers = re.findall(r'[5-7]', string, re.X)
Dan Johnson40,532 Points
If you're looking to grab the numbers individually you could do something like this:
This will match those digits and prevent grouping them if they're adjacent, e.g. "150" will map to '1' and '5' instead of "15".