Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Brandon Wall
5,512 PointsLessons on Sets {} ?
So I'm on the part of the python course track of regular expressions, and Kenneth Love is talking about sets defined with square brackets as parameters that our expressions can search for. I've been waiting for actual sets to be introduced and I thought for sure it would be taught way back when we learned about lists and dictionaries and tuples in python collections. However it was not.
A set is defined with curly braces, it is a disordered collection of unique elements if my understanding is correct. When we define a search parameter in a regular expression, a set is defined with square brackets. How about when we search for lets say a sequence of digit characters like when we were searching for phone numbers in names.txt with
re.findall([-\w ]*, \s[-\w ]+\t) # Last and first names
re.findall(r'\d{3}-\d{3}-\d{4}') #simplified a bit for sake of the question
I know the number within the curly braces is basically saying 'find this character x times' and we also use the curly braces when calling a .format. When do actual sets, the data type, come into play? It's just all a little confusing >.<
1 Answer
Kenneth Love
Treehouse Guest TeacherWe don't have any formal material covering set() at this point. I'm planning on adding some real soon (likely before 2016 but don't hold me to that). That said, you'll find yourself using set() way less than the other data types so that's why I haven't covered it in depth yet.
And, just to be clear, sets in regex and sets in a mathematical or programming sense are not at all related.