我需要一个匹配以字边界结尾的表达式的正则表达式,但不将连字符视为边界.即获得所有匹配的表达式
type ([a-z])\b
Run Code Online (Sandbox Code Playgroud)
但不匹配,例如
type a-1
Run Code Online (Sandbox Code Playgroud)
改写:我想要一个等价的边界运算符\ b,而不是使用单词字符类[A-Za-z0-9_],使用扩展类:[A-Za-z0-9_-]
这是Ryan Frank在forums.mysql.com上提出的问题,我也面临这个问题.
我在SELECT语句的开头有以下内容:
SELECT accounts.id, accounts.company, accounts.first, accounts.last,
COUNT(DISTINCT accounts_log.login_time) AS visits,
COUNT(DISTINCT accounts_log.ip_address) AS visitors,
COUNT(DISTINCT documents_log.access_time) AS docs,
MAX(accounts_log.login_time) AS login_time
FROM accounts
Run Code Online (Sandbox Code Playgroud)
这将返回我需要的所有变量; 但是,我想将使用COUNT(DISTINCT)的变量限制为日期范围.我不能在FROM子句后使用WHERE子句.例如:
FROM accounts
WHERE accounts_log.login_time >='$search_from' AND accounts_log.login_time <='$search_to'
Run Code Online (Sandbox Code Playgroud)
不会工作,因为它不会给我所有帐户,就像我需要的那样.
我正在寻找类似的东西:
COUNT(DISTINCT accounts_log.login_time WHERE accounts_log.login_time >='$search_from' AND accounts_log.login_time <='$search_to') AS visits
Run Code Online (Sandbox Code Playgroud)
PS我知道上面的内容不起作用,并且已经用完了语法选项.
我需要从SEC网站下载大约200万个文件.每个文件都有一个唯一的URL,平均为10kB.这是我目前的实施:
List<string> urls = new List<string>();
// ... initialize urls ...
WebBrowser browser = new WebBrowser();
foreach (string url in urls)
{
browser.Navigate(url);
while (browser.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();
StreamReader sr = new StreamReader(browser.DocumentStream);
StreamWriter sw = new StreamWriter(), url.Substring(url.LastIndexOf('/')));
sw.Write(sr.ReadToEnd());
sr.Close();
sw.Close();
}
Run Code Online (Sandbox Code Playgroud)
预计的时间大约是12天......有更快的方法吗?
编辑:顺便说一句,本地文件处理只占7%的时间
编辑:这是我最后的实现:
void Main(void)
{
ServicePointManager.DefaultConnectionLimit = 10000;
List<string> urls = new List<string>();
// ... initialize urls ...
int retries = urls.AsParallel().WithDegreeOfParallelism(8).Sum(arg => downloadFile(arg));
}
public int downloadFile(string url)
{
int retries = 0; …Run Code Online (Sandbox Code Playgroud) 我有一个字符串列表,我想按 Python 3.6 中的两个自定义键函数对其进行排序。将多排序方法(按较小键排序,然后按主键排序)与多键方法(将键作为元组(major_key, lesser_key))进行比较,我可以看到后者比前者慢 2 倍以上,这是惊讶,因为我认为它们是等价的。我想了解为什么会这样。
import random
from time import time
largest = 1000000
length = 10000000
start = time()
lst = [str(x) for x in random.choices(range(largest), k=length)]
t0 = time() - start
start = time()
tmp = sorted(lst, key=lambda x: x[::2])
l1 = sorted(tmp, key=lambda x: ''.join(sorted(x)))
t1 = time() - start
start = time()
l2 = sorted(lst, key=lambda x: (''.join(sorted(x)), x[::2]))
t2 = time() - start
print(f'prepare={t0} multisort={t1} multikey={t2} slowdown={t2/t1}')
assert l1 == l2
Run Code Online (Sandbox Code Playgroud) 尝试从 python 列表中索引或删除 numpy 数组项,第一项不会按预期失败。
import numpy as np
# works:
lst = [np.array([1,2]), np.array([3,4])]
lst.index(lst[0])
# fails with: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
lst = [np.array([1,2]), np.array([3,4])]
lst.index(lst[1])
Run Code Online (Sandbox Code Playgroud)
我理解为什么第二个失败,我想理解为什么第一个有效。
我正在使用yahoo finance api获取股票和股票期权数据.这曾经工作:
http://quote.yahoo.com/d/quotes.csv?s=VCR.X&f=l1c1n
这曾经是Visa的选择.这不再适用了,当我去雅虎财务时,他们的选项符号现在都不同了,看起来像这样:
VEH100220P00055000
这是Visa现在的选择.如果我将那个长插入到网址中,它也无法正常工作.有谁知道他们是否正在改变他们的选择并打破了这个?
给定一个正则表达式字符类/集,如何获得所有匹配字符的列表(在python 3中).例如:
[\dA-C]
Run Code Online (Sandbox Code Playgroud)
应该给
['0','1','2','3','4','5','6','7','8','9','A','B','C']
Run Code Online (Sandbox Code Playgroud) 在GNU Octave中,矩阵划分如何工作?
而不是做
1./[1;1]
Run Code Online (Sandbox Code Playgroud)
我不小心做了
1/[1;1]
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,这会产生:
[0.5, 0.5]
Run Code Online (Sandbox Code Playgroud)
横向案例:
1/[1,1]
Run Code Online (Sandbox Code Playgroud)
给出了预期的:
error: operator /: nonconformant arguments (op1 is 1x1, op2 is 1x2)
Run Code Online (Sandbox Code Playgroud)
有人可以解释[0.5,0.5]的结果吗?
我有一个计数器字典,例如:
from collections import Counter, defaultdict
numbers = defaultdict(Counter)
numbers['a']['first'] = 1
numbers['a']['second'] = 2
numbers['b']['first'] = 3
Run Code Online (Sandbox Code Playgroud)
我想得到总和:1 + 2 + 3 = 6
在python 3中执行此操作的最简单/惯用方法是什么?
尝试对希伯来语使用稀疏句子标记。
import spacy
nlp = spacy.load('he')
doc = nlp(text)
sents = list(doc.sents)
Run Code Online (Sandbox Code Playgroud)
我得到:
Warning: no model found for 'he'
Only loading the 'he' tokenizer.
Traceback (most recent call last):
...
sents = list(doc.sents)
File "spacy/tokens/doc.pyx", line 438, in __get__ (spacy/tokens/doc.cpp:9707)
raise ValueError( ValueError: Sentence boundary detection requires the dependency parse, which requires data to be installed. For more info, see the documentation: https://spacy.io/docs/usage
Run Code Online (Sandbox Code Playgroud)
该怎么办?
我有一系列对(名称,分数),有重复的名字.我想获得每个名字的最高分.名称标签本身对于最终结果是可选的.这是一个有效的实施:
from collections import defaultdict
scores = (('eyal', 76), ('alex', 50), ('oded', 90), ('eyal', 100), ('alex', 99))
distinct = defaultdict(set)
for score in scores:
distinct[score[0]].add(score[1])
max_scores = [max(distinct[k]) for k in distinct]
print (max_scores)
Run Code Online (Sandbox Code Playgroud)
我想知道,这可以使用字典理解一步完成吗?
将段落定义为两边用双新行('\n \n')分隔的多行字符串.如果存在包含某个字符串('BAD')的段落,我想用一些其他标记('GOOD')替换该段落(即包含BAD的任何文本,直到最接近的前一行和后面的双重换行符).这应该是一个python 3正则表达式.
我有这样的文字:
dfsdf\n
sdfdf\n
\n
blablabla\n
blaBAD\n
bla\n
\n
dsfsdf\n
sdfdf
Run Code Online (Sandbox Code Playgroud)
应该:
dfsdf\n
sdfdf\n
\n
GOOD\n
\n
dsfsdf\n
sdfdf
Run Code Online (Sandbox Code Playgroud)