假设我有一个整数类型列表[1; 2; 3; 4; 5; 6; 7; 我希望一次匹配前三个元素.没有嵌套的匹配语句有没有办法做到这一点?
例如,它可以这样做吗?
let rec f (x: int list) : (int list) =
begin match x with
| [] -> []
| [a; b; c]::rest -> (blah blah blah rest of the code here)
end
Run Code Online (Sandbox Code Playgroud)
我可以使用long嵌套方法,它将是:
let rec f (x: int list) : (int list) =
begin match x with
| [] -> []
| h1::t1 ->
begin match t1 with
| [] -> []
| h2::t2 ->
begin match t2 with
| [] …Run Code Online (Sandbox Code Playgroud) 在lxml中,我使用xpath来选择表中的所有tr(具有不同数量的行),除了包含乱码的最后两行.
是否存在排除最后两行的模式匹配?我正在浏览xpath教程,显然有一个"except"运算符和一个"last()",但似乎无法使我的代码工作.
到目前为止,我有这个.我该添加什么来使它排除最后两行?主要问题是tr的数量有所不同.
result = doc.xpath("//tr")
Run Code Online (Sandbox Code Playgroud)
我想我可以把它变成一个列表,只删除最后两个元素,但有没有更容易/优雅的解决方案?
提前致谢!