我正在尝试创建一个二维数组类,但遇到了问题。我能想到的最好方法是将索引的元组传递给 get/setitem,并将其解压缩到函数中。不幸的是,实现看起来非常混乱:
class DDArray:
data = [9,8,7,6,5,4,3,2,1,0]
def __getitem__ (self, index):
return (self.data [index [0]], self.data [index [1]])
def __setitem__ (self, index, value):
self.data [index [0]] = value
self.data [index [1]] = value
test = DDArray ()
print (test [(1,2)])
test [(1, 2)] = 120
print (test [1, 2])
Run Code Online (Sandbox Code Playgroud)
我试着让它接受更多参数:
class DDArray:
data = [9,8,7,6,5,4,3,2,1,0]
def __getitem__ (self, index1, index2):
return (self.data [index1], self.data [index2])
def __setitem__ (self, index1, index2, value):
self.data [index1] = value
self.data [index2] = value
test …Run Code Online (Sandbox Code Playgroud) 我有一小部分代码表现不像我预期的那样:
tempTest = do
(_,tHand) <- openTempFile "." "tempTest.txt"
hPutStr tHand "Test!"
read <- hGetContents tHand
putStrLn read
Run Code Online (Sandbox Code Playgroud)
它正确地写入文件,但当被要求将内容显示到屏幕时,它只显示一个新行(没有任何引号).鉴于这是多么简单,我假设我误解了getContents的工作原理.根据我的理解,它以块的形式读取文件,而不是一次读取所有文件; 这可以防止内存被正在读取的大量文件填满.为什么"阅读"没有从hGetContents接收任何内容?这里的任何帮助都将不胜感激.
int main() {
std::cout << "\u2654" << std::endl; // Result #1: ?
std::cout << U'\u2654' << std::endl; // Result #2: 9812
std::cout << U'?' << std::endl; // Result #3: 9812
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我无法理解Unicode如何与C++一起工作.为什么文字输出终端中的文字?
我有点想要这样的事情;
char32_t txt_representation() { return /* Unicode codepoint */; }
Run Code Online (Sandbox Code Playgroud)
注意:源是UTF-8,终端,坐在macOS Sierra,CLion上.
我想要一个更小的方式来写这个条件我试图简化它但它不适用于我
if(( data.includes(userId) || data.includes(userId.toString()) || data.includes(username) )) console.log(true)
Run Code Online (Sandbox Code Playgroud)
这个条件非常好,但我想要它的简化版本
在 Windows 上使用 clang 编译器会抛出“预处理器表达式启动时的无效标记”
#if __WORDSIZE == 64
Run Code Online (Sandbox Code Playgroud)
./bits/types.h:42:16:错误:预处理器表达式开头的标记无效
为了确保 __WORDSIZE 已定义,我添加了
#define __WORDSIZE
Run Code Online (Sandbox Code Playgroud)
./bits/wordsize.h:8:9: warning: '__WORDSIZE' macro redefined [-Wmacro-redefined]这会按预期发出警告
这是我尝试过的
let somejsvar = 'hello world'
document.getElementById('id_element_in_html').innerHTML = '<li> somejsvar </li>';
Run Code Online (Sandbox Code Playgroud)
我的输出:
>>> - somejsvar
Run Code Online (Sandbox Code Playgroud)
所需的输出:
>>> - hello world
Run Code Online (Sandbox Code Playgroud) 我进行了这样的连锁条件测试:
if find_num_3 != None and find_num_3 != i and find_num_3 != j: #don't reproduce itself
Run Code Online (Sandbox Code Playgroud)
在代码中:
for i in range(len(nums)):
num_1= nums[i]
sub_target = target - num_1
logging.debug(f"level_1_lookup: {lookup}")
for j in range(i+1, len(nums)):
num_2 = nums[j] #
num_3 = sub_target - num_2
find_num_3 = lookup.get(num_3) #
if find_num_3 != None and find_num_3 != i and find_num_3 != j: #don't reproduce itself
result = [num_1, num_2, num_3]
triplets.append(result)
logging.debug(f"lookup: {lookup} sub_nums: {nums[j:]} \nresult: {result}")
logging.info(f"\ttriplets: {triplets}\n\n\n\n")
return triplets
Run Code Online (Sandbox Code Playgroud)
如何将长链转变为紧凑的短结构。
在JavaScript中,可以执行以下操作:
function foo(arg1, arg2, arg3) {
...
}
var others = [ 'two', 'three' ];
foo('one', ...others); // same as foo('one', 'two', 'three')
Run Code Online (Sandbox Code Playgroud)
在Clojure中,可以这样接受“变量args”:
function foo(arg1, arg2, arg3) {
...
}
var others = [ 'two', 'three' ];
foo('one', ...others); // same as foo('one', 'two', 'three')
Run Code Online (Sandbox Code Playgroud)
但是要将它们与其他arg组合使用,您必须这样做:
(defn foo [arg1 & others]
...)
Run Code Online (Sandbox Code Playgroud)
坦白说,这真的很丑。当您需要重复执行操作时,这也是不可能的:
(apply foo (concat '("one") others))
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?如果不是,那么在这种recur情况下是否有任何方法可以实现?
我需要将浮动比率转换为等效的整数
0.5:1 ---应转换为---> 1:2
0.5:0.6:1 ---应转换为---> 5:6:10(最小整数比)
我的谷歌搜索在这方面没有任何结果
我是 VS Code 的初学者,完成新安装并面临以下问题:
SyntaxError: invalid syntax
>>> & C:/ProgramData/Anaconda3/python.exe c:/Users/lenovo/Desktop/python/python1.py
File "<stdin>", line 1
& C:/ProgramData/Anaconda3/python.exe c:/Users/lenovo/Desktop/python/python1.py
^
SyntaxError: invalid syntax
>>> print("hhi")
hhi
>>> & C:/ProgramData/Anaconda3/python.exe c:/Users/lenovo/Desktop/python/python1.py
File "<stdin>", line 1
& C:/ProgramData/Anaconda3/python.exe c:/Users/lenovo/Desktop/python/python1.py
^
SyntaxError: invalid syntax
>>> & C:/ProgramData/Anaconda3/python.exe c:/Users/lenovo/Desktop/python/python1.py
File "<stdin>", line 1
& C:/ProgramData/Anaconda3/python.exe c:/Users/lenovo/Desktop/python/python1.py
^
SyntaxError: invalid syntax
>>> print("hi")
hi
>>>
Run Code Online (Sandbox Code Playgroud) python ×4
javascript ×2
algorithm ×1
c++ ×1
clang ×1
clojure ×1
haskell ×1
html ×1
if-statement ×1
macros ×1
math ×1
preprocessor ×1
python-3.x ×1
unicode ×1