我正在尝试编写一个用于添加2D矢量的函数.我正在尝试组合map()函数,使用函数获取列表zip()(将拉链2个元组).
这是代码:
a = (1, 2)
b = (3, 4)
c = list(map(lambda x, y: x+y, list(zip(a, b))))
print(c)
Run Code Online (Sandbox Code Playgroud)
所以我看到它的方式,zip(a, b)返回一个包含以下元组的zip对象:(1,3),(2,4).然后将其转换为列表.我收到以下错误:
TypeError :()缺少1个必需的位置参数:'y'
所以我的猜测是lambda函数没有取每个元组中的第二个数字.
有没有办法做到这一点?
我正在尝试在C中实现一个链表,我很难搞清楚为什么我在编译时遇到以下错误:
entryList.c:7:11: error: 'tmp' undeclared (first use in this function)
entry * tmp = NULL;
entryList.c:7:11: note: each undeclared identifier is reported only once for
each function it appears in
^
Run Code Online (Sandbox Code Playgroud)
我已经为这个程序写了一些链表,它们都使用了类似的语法,但编译器只抱怨这个.
我在header.h中有我的结构定义:
/*definition of entry type*/
typedef struct entry
{
char * label;
short int address;
struct entry * next;
} entry;
Run Code Online (Sandbox Code Playgroud)
在entryList.c中,我正在编写一个函数来将一个节点添加到链表中.
#include "header.h"
static entry * head = NULL;
void addEntry(char * entry, int line)
{
entry * tmp = NULL;
char * label = NULL;
tmp …Run Code Online (Sandbox Code Playgroud)