使用set和zip时不确定为什么这个有效:
>>> a = ([1])
>>> b = ([2])
>>> set(zip(a,b))
{(1, 2)}
Run Code Online (Sandbox Code Playgroud)
但这个没有?
>>> a = ([1],[2])
>>> b = ([3],[4])
>>> set(zip(a,b))
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
set(zip(a,b))
TypeError: unhashable type: 'list'
Run Code Online (Sandbox Code Playgroud)
期望的结果(1,3)(2,4)
这样做的正确方法是什么?
谢谢!
约翰
我为什么p->a()打电话感到困惑B::a()?C++文档/标准中是否有一个段落可以很好地描述这种行为?
#include <iostream>
using namespace std;
class A {
public:
A() { cout << "A ctor" << endl; a_instance = this; }
static A *get_instance() { return a_instance; }
static A *a_instance;
void virtual a() { cout << "From base class" << endl; }
};
class B : public A {
public:
B() { cout << "B ctor" << endl; b_instance = this; }
static B *get_instance() { return b_instance; }
static B *b_instance;
void virtual …Run Code Online (Sandbox Code Playgroud)