这会在从开头删除字符的同时打印单词。
word = "word"
length = len(word)
for s in range(0, length):
print(word[s:])
s=+1
Run Code Online (Sandbox Code Playgroud)
所以输出是
word
ord
rd
d
Run Code Online (Sandbox Code Playgroud)
如何翻转它,以便在删除字符时向后打印单词?
这样输出将是:
drow
row
ow
w
Run Code Online (Sandbox Code Playgroud) 我有以下代码,其中std :: tuple可与nullptr一起使用,但不适用于NULL。
#include <iostream>
#include <tuple>
int main()
{
tuple<int*> t1, t2;
t1 = std::make_tuple(NULL);
t2 = std::make_tuple(nullptr);
}
Run Code Online (Sandbox Code Playgroud)
当使用C ++ 11编译时,该代码在使用nullptr时有效,但是在使用NULL的情况下会出现以下错误。
In file included from tuple.cpp:2:
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/tuple:447:8: error: assigning to 'int *' from incompatible type 'long'
= std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/tuple:575:36: note: in instantiation of function template specialization 'std::_Tuple_impl<0, int *>::operator=<long>' requested here
static_cast<_Inherited&>(*this) = std::move(__in);
^
tuple.cpp:13:8: note: in instantiation of function template specialization 'std::tuple<int *>::operator=<long, void>' requested here
t1 = std::make_tuple(NULL);
^
1 error generated.
Run Code Online (Sandbox Code Playgroud)
在这里,NULL的类型是long …
如果我在本地命令行中使用 grep 和 sort 等执行 find 命令,我会得到如下返回的行:
# find ~/logs/ -iname 'status' | xargs grep 'last seen' | sort --field-separator=: -k 4 -g
0:0:line:1
0:0:line:2
0:0:line:3
Run Code Online (Sandbox Code Playgroud)
如果我通过 ssh 执行相同的命令,则返回的文本将不带换行符打印,如下所示:
# VARcmdChk="$(ssh ${VARuser}@${VARserver} "find ~/logs/ -iname 'status' | xargs grep 'last seen' | sort --field-separator=: -k 4 -g")"
# echo ${VARcmdChk}
0:0:line:1 0:0:line:2 0:0:line:3
Run Code Online (Sandbox Code Playgroud)
我试图理解为什么 ssh 正在清理返回的文本,以便将换行符转换为空格。我还没有尝试输出到文件,然后使用 scp 将其拉回来。似乎很浪费,因为我只想在本地查看远程结果。
因此,我需要使用 ECC spec256k1 从相应的 256 位数字中获取公钥。
因此,假设我从任何密码短语中使用 sha256 获取私钥,如下所示:
>>> import hashlib
>>> private_key = hashlib.sha3_256(b"Led Zeppelin - No Quarter").hexdigest()
>>> private_key
'c0b279f18074de51d075b152c8ce78b7bddb284e8cfde19896162abec0a0acce'
Run Code Online (Sandbox Code Playgroud)
如何从该私钥获取公钥?我需要将公钥打印为字符串。
遵循https://www.tidyverse.org/blog/2020/02/glue-strings-and-tidy-eval/ 中的示例
你如何将变量传递给这个函数?
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.6.2
#> Warning: package 'tidyr' was built under R version 3.6.2
mean_by <- function(data, by, var, prefix = "avg") {
data %>%
group_by({{ by }}) %>%
summarise("{prefix}_{{ var }}" := mean({{ var }}, na.rm = TRUE))
}
mean_by(mtcars, by = cyl, var = mpg, prefix = "avg")
#> # A tibble: 3 x 2
#> cyl avg_mpg
#> <dbl> <dbl>
#> 1 4 26.7
#> …Run Code Online (Sandbox Code Playgroud) 我尝试在 Windows 10 上安装 win32print,如下所示:
pip3.exe install win32print
Run Code Online (Sandbox Code Playgroud)
错误:找不到满足 win32print 要求的版本(来自版本:无)
错误:找不到 win32print 的匹配发行版
如何修复它并在 Windows 10 上安装 win32print?
我有一个包含对象列表的字典作为
objects = {'A1': obj_1,
'A2': obj_2,
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个字符串
cmd = '(1.3A1 + 2(A2 + 0.7A3)) or 2(A4 to A6)'
Run Code Online (Sandbox Code Playgroud)
我想把它翻译成一个命令
max( 1.3*objects['A1'] + 2*(objects['A2'] + 0.73*objects['A3']), 2*max(objects['A4'], objects['A5'], objects['A6']))
Run Code Online (Sandbox Code Playgroud)
由于没有找到更好的选择,我开始从头开始编写解析器。
个人注意:我不认为将 150 行代码附加到 SO 问题是好的做法,因为这意味着读者应该阅读并理解它,这是一项艰巨的任务。尽管如此,我之前的问题被否决了,因为我没有提出我的解决方案。所以你来了...
import re
from more_itertools import stagger
def comb_to_py(string, objects):
# Split the line
toks = split_comb_string(string)
# Escape for empty string
if toks[0] == 'none':
return []
# initialize iterator
# I could use a deque here. Let's see what works the best …Run Code Online (Sandbox Code Playgroud) 我需要将绘制蓝色图形的数组拆分为多个新数组。每当数组中数字的值从负数变为正数或反之亦然时,它应该将数字保存在新数组中。所以结果是多个数组,要么是正数,要么是负数。该代码并不意味着仅仅将 2 个不同数组中的正数和负数组合起来。重要的是(对于这个例子)我最终得到 3 个不同的数组(第一:只有负数,第二:只有正数,第三:再次只有负数)。
我很高兴能得到任何帮助。谢谢!
蓝线图的图像
在这种情况下:
Difference (blue line) = [-20.2 -19.7 -19.2 -18.9 -18.8 -18.8 -18.9 -18.9 -18.9 -18.9 -18.9 -18.9 -19. -19.1 -19.1 -18.9 -18.5 -18.3 -18.9 -20.8 -24.1 -27.2 -28.1 -24.6 19.1 63.4 104.2 143.8 140.9 120.3 91.7 64.5 46.4 38.2 39. 47.8 63.3 82.9 103.5 122.1 136.4 147.1 155.3 162.5 169.7 177. 184.4 191.8 199.2 207.5 217.7 230.7 246.3 260.2 266.7 260.3 237.5 203.1 164.1 127.3 98. 75.3 56.7 39.9 22.7 5.5 -11.2 -26.5 …Run Code Online (Sandbox Code Playgroud) 我希望当图表上的线低于 0 时为红色且高于绿色。我试图弄清楚我自己,但是,当我只需要低于 y=0 的颜色时,该代码在周五至周六的整个部分为我提供了一种颜色(“红色”,因为它低于 0)。
a<-structure(list(group = c("Total", "Total", "Total", "Total",
"Total", "Total", "Total"), measure = c("sales", "sales", "sales",
"sales", "sales", "sales", "sales"), day = structure(1:7, .Label = c("MONDAY",
"TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"
), class = "factor"), variable = structure(c(1L, 1L, 1L, 1L,
1L, 1L, 1L), .Label = c("ALL", "DE", "BE", "NL", "AUS", "ES",
"IT", "FR", "PO"), class = "factor"), value = c(2400000, 3750000,
3400000, 3100000, 2300000, 3600000, 3100000), per_mtoday = c(2400000,
2400000, 2400000, 2400000, 2400000, 2400000, …Run Code Online (Sandbox Code Playgroud) 如果我有以下包含一些数据的向量,例如
a <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
Run Code Online (Sandbox Code Playgroud)
假设我想将这 20 个值按照排列顺序分为 4 个,如下所示
[1] "1\n2\n3\n4" "5\n6\n7\n8" "9\n10\n11\n12" "13\n14\n15\n16" "17\n18\n19\n20"
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?我从这个函数开始paste,但我被困住了:(我假设它会涉及一个 for 循环。
paste(a)
Run Code Online (Sandbox Code Playgroud)