Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. DreamPie 1.2.1 >>> import re >>> dir(re) 0: ['A', 'ASCII', 'DEBUG', 'DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE', 'Match', 'NOFLAG', 'Pattern', 'PatternError', 'RegexFlag', 'S', 'Scanner', 'U', 'UNICODE', 'VERBOSE', 'X', '_MAXCACHE', '_MAXCACHE2', '_ZeroSentinel', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_cache', '_cache2', '_casefix', '_compile', '_compile_template', '_compiler', '_constants', '_parser', '_pickle', '_special_chars_map', '_sre', '_zero_sentinel', 'compile', 'copyreg', 'enum', 'error', 'escape', 'findall', 'finditer', 'fullmatch', 'functools', 'match', 'purge', 'search', 'split', 'sub', 'subn'] [About 61 more lines. Double-click to unfold] >>> [x for x in dir(re) if x == x.upper()] 1: ['A', 'ASCII', 'DEBUG', 'DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE', 'NOFLAG', 'S', 'U', 'UNICODE', 'VERBOSE', 'X', '_MAXCACHE', '_MAXCACHE2'] >>> re.VERBOSE 2: re.VERBOSE >>> int(re.VERBOSE) 3: 64 >>> bin(int(re.VERBOSE)) 4: '0b1000000' >>> int(re.MULTILINE) 5: 8 >>> bin(int(re.MULTILINE)) 6: '0b1000' >>> 64 | 8 7: 72 >>> bin(72) 8: '0b1001000' >>> bin(72)[2:] 9: '1001000' >>> bin(72)[2:].zfill(8) 10: '01001000' >>> format(72, '08b') 11: '01001000' >>> format(64, '08b') 12: '01000000' >>> format(8, '08b') 13: '00001000' >>> re.VERBOSE | re.MULTILINE 14: re.MULTILINE|re.VERBOSE >>> int(re.VERBOSE | re.MULTILINE) 15: 72 >>> from collections import defaultdict >>> attrs = dict() ... for x in dir(re): ... if x == x.upper() and not x.startswith('_'): ... value = int(getattr(re, x)) ... attrs[value] = x ... print(attrs) {256: 'ASCII', 128: 'DEBUG', 16: 'S', 2: 'IGNORECASE', 4: 'LOCALE', 8: 'MULTILINE', 0: 'NOFLAG', 32: 'UNICODE', 64: 'X'} >>> attrs = dict() ... for x in dir(re): ... if x == x.upper() and not x.startswith('_'): ... value = int(getattr(re, x)) ... if value in attrs: ... attrs[value] = x ... print(attrs) {} >>> attrs = dict() ... for x in dir(re): ... if x == x.upper() and not x.startswith('_'): ... value = int(getattr(re, x)) ... if value not in attrs: ... attrs[value] = set() ... attrs[value].add(x) ... print(attrs) {256: {'ASCII', 'A'}, 128: {'DEBUG'}, 16: {'S', 'DOTALL'}, 2: {'IGNORECASE', 'I'}, 4: {'L', 'LOCALE'}, 8: {'M', 'MULTILINE'}, 0: {'NOFLAG'}, 32: {'U', 'UNICODE'}, 64: {'X', 'VERBOSE'}} >>> attrs = defaultdict(set) ... for x in dir(re): ... if x == x.upper() and not x.startswith('_'): ... value = int(getattr(re, x)) ... #if value not in attrs: ... # attrs[value] = set() ... attrs[value].add(x) ... print(attrs) defaultdict(<class 'set'>, {256: {'ASCII', 'A'}, 128: {'DEBUG'}, 16: {'S', 'DOTALL'}, 2: {'IGNORECASE', 'I'}, 4: {'L', 'LOCALE'}, 8: {'M', 'MULTILINE'}, 0: {'NOFLAG'}, 32: {'U', 'UNICODE'}, 64: {'X', 'VERBOSE'}}) >>> attrs = defaultdict(set) ... for x in dir(re): ... if x == x.upper() and not x.startswith('_'): ... value = int(getattr(re, x)) ... attrs[value].add(x) ... print(attrs) defaultdict(<class 'set'>, {256: {'ASCII', 'A'}, 128: {'DEBUG'}, 16: {'S', 'DOTALL'}, 2: {'IGNORECASE', 'I'}, 4: {'L', 'LOCALE'}, 8: {'M', 'MULTILINE'}, 0: {'NOFLAG'}, 32: {'U', 'UNICODE'}, 64: {'X', 'VERBOSE'}}) >>>