pythonic way to rewrite an assignment in an if statement

前端 未结 7 833
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 10:37

Is there a pythonic preferred way to do this that I would do in C++:


for s in str:
    if r = regex.match(s):
        print r.groups()

I r

7条回答
  •  清酒与你
    2020-12-19 11:31

    This might be an overly simplistic answer, but would you consider this:

    for s in str:
        if regex.match(s):
            print regex.match(s).groups()
    

提交回复
热议问题