你好社区,
[序言]:
我来自 BASH 脚本背景(仍在学习那里),并决定冒险进入另一种语言可能会有益于我的学习过程。对我来说,自然的选择似乎是 Python。我开始学习了一下,并且一直在学习 www.learnpython.org 上的练习。特别是模块和包。
[ 问题 ] :
Import模块re和printout 按字母顺序排序,模块中包含单词的所有函数find。
[尝试]:
# import the module.
import re
# store output of dir(re) in reLST as string list.
''' I believe that's what happens, correct? '''
reLST = dir(re)
# iterate over reLST and assign m strings matching word containing find.
for element in reLST:
    m = re.match("(find\w+)", element)
# Here it prints out the matches, but only using the function .groups()
''' Won't work using print sorted(m)  ---why? '''
# Found tutorial online, but no real understanding of .groups() function use.     
    if m:
        print sorted(m.groups())
[预期输出]:
 
['findall','finditer']
[我的输出]:
 
['findall'] 
['finditer']
[问题]:
从技术上讲,该代码有效并且确实输出了从 抓取的所有字符串dir(re),但在新行上。我猜这是作为.groups()功能的一部分完成的?以正确格式获得所需输出的好方法是什么?