2gua's recent timeline updates
2gua

2gua

我是2gua
V2EX member #35291, joined on 2013-03-06 10:53:52 +08:00
☑编程 ☑读书 ☑太极拳
2gua's recent replies
Jul 11, 2019
Replied to a topic by Dragonish3600 Python Python 正则表达式合并的问题
from typing import Optional, Match, Pattern, Tuple
import re


def matchs(target: str) -> Optional[str]:
pat: Pattern[str] = re.compile(r"port\s*(\d+)|Logon ID:\s*(\w+)")
res: Optional[Match[str]] = re.search(pat, target)
if res:
g: Tuple[Optional[str], Optional[str]] = res.groups()
return g[0] if g[0] else g[1]
return None
不知道 Python 好在哪儿。就是每每用到它时,感觉写代码很愉悦就是了。比如这样我就觉得很方便:
In [79]: m1 = {'a': 1, 'b': 2}

In [80]: m2 = {'c': 3, 'd': 4}

In [81]: {**m1, **m2}
Out[81]: {'a': 1, 'b': 2, 'c': 3, 'd': 4}
Feb 4, 2018
Replied to a topic by bingod Python 2018 年,你选择 Flask 还是 Django?
Flask 玩腻,现在选 Django。
lst = [['a', 'b', 'c'], ['@', '#', '$', '%'], ['1', '2']]

1.
import itertools
[list(i) for i in itertools.product(*lst)]

2.
def cross(lst):
def swim(l, t, res):
if len(l) == 0:
res += [t]
return
for i in l[0]:
swim(l[1:], t + [i], res)

res = []
swim(lst, [], res)
return res
Oct 11, 2016
Replied to a topic by barretlee 程序员 你用的哪个编辑器, ST/Atom/VSC?
VS Code.
Dec 7, 2013
Replied to a topic by h2sky 问与答 你喜欢去哪个网站听音乐?
douban.fm
虾米
如果出于了解的目的,就不一定会写项目。
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2677 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 18ms · UTC 02:05 · PVG 10:05 · LAX 19:05 · JFK 22:05
♥ Do have faith in what you're doing.