示例:这是合法的C++ 14吗?
#include <iostream>
static int d() {
return 42;
}
static int e(int d = d()) {
return d;
}
int main() {
std::cout << e() << " " << e(-1) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
g ++ 5.4 -std=c++14喜欢它,但clang ++ 3.8 -std=c++14抱怨:
samename.cxx:3:23: error: called object type 'int' is not a function or function pointer
static int e(int d = d()) {return d;}
~^
Run Code Online (Sandbox Code Playgroud) 我正在使用Python,我需要将我的.csv导入数据分为两部分,一个是训练和测试集,EG 70%训练和30%测试.
我不断收到各种错误,比如'list' object is not callable等等.
这有什么简单的方法吗?
谢谢
编辑:
代码是基本的,我只是想分割数据集.
from csv import reader
with open('C:/Dataset.csv', 'r') as f:
data = list(reader(f)) #Imports the CSV
data[0:1] ( data )
Run Code Online (Sandbox Code Playgroud)
TypeError: 'list' object is not callable
我有一个这样的嵌套列表:
l = [['A', ['A', 'B', ['A', 'B', 'C'], ['A', 'B', 'D']], ['A', 'D', ['A', 'D', 'A']], ['A', 'C', ['A', 'C', 'B'], ['A', 'C', 'A']], ['A', 'A', ['A', 'A', 'D']]]]
Run Code Online (Sandbox Code Playgroud)
我想将它分成所有单个列表的列表,如下所示:
k = [['A'], ['A', 'B'], ['A', 'B', 'C'], ['A', 'B', 'D'], ['A', 'D'], ['A', 'D', 'A'], ['A', 'C'], ['A', 'C', 'B'], ['A', 'C', 'A'], ['A', 'A'], ['A', 'A', 'D']]
Run Code Online (Sandbox Code Playgroud)
我通过创建以下函数尝试了这个:
def un_nest(l):
k=[]
for item in l:
if type(item) is list:
un_nest(item)
else:
k+=[item]
print(k)
Run Code Online (Sandbox Code Playgroud)
我得到了所需的输出,但我不知道如何将其转换为列表.我得到的输出是:
['A', 'B', 'C'] …Run Code Online (Sandbox Code Playgroud) python ×2
c++ ×1
csv ×1
data-science ×1
list ×1
nested-lists ×1
overloading ×1
python-3.4 ×1
scope ×1
split ×1