Great that you continue learning.
I would just like to remind you that converting a list of names (as strings) to a single string and trying to filter individual names in the combined string is not certainly an optimal approach. We can see that as a kind of playful exercise with regexes. The for
loop will allow you to use a much better approach.
Closer examination of the output of your last program shows that in the output some quotes are replaced by double quotes and there are extra quotes and double quotes. To better demonstrate what is going on, let’s print individual items of the result of re.findall()
on separate lines.
Your program with just a different way of printing the result:
import math
MODULE_NAME = math
import re
working_string = dir(MODULE_NAME)
pattern_non_dunder = re.compile(r"(\b[a-z][^_A-Z0-9]+\b[^_a-z])")
result_list = re.findall(pattern_non_dunder, str(working_string,))
for item in result_list:
print(item)
The printed result (one item per line):
acos', 'acosh', 'asin', 'asinh', 'atan'
atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp'
fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log'
modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp'
When you print that list directly, Python adds quotes around the individual strings (lines in our output) and separates them by commas.