Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于列表的Python Django Lambda表达式_Python - Fatal编程技术网

用于列表的Python Django Lambda表达式

用于列表的Python Django Lambda表达式,python,Python,我需要用Python更新一个列表,它是: data = [{' Customers ','null,blank '},{' CustomersName ','max=50,null,blank '},{' CustomersAddress ','max=150,blank '},{' CustomersActive ','Active '}] 我想编写一个Lambda表达式来存储列表中的Customers和CustomersName,并删除空格。 我是Python的新手,没有任何知识 在我看来

我需要用Python更新一个列表,它是:

data = [{' Customers ','null,blank '},{' CustomersName ','max=50,null,blank '},{' CustomersAddress ','max=150,blank '},{' CustomersActive ','Active '}]
我想编写一个Lambda表达式来存储列表中的Customers和CustomersName,并删除空格。
我是Python的新手,没有任何知识

在我看来,您已经在一个列表中声明了字典,但是Dict是错误的,它应该是{“key”:“value”},所以我假设您需要将其更改为List,如下所示:

  data = [[' Customers ','null,blank '],[' CustomersName ','max=50,null,blank '],[' CustomersAddress ','max=150,blank '],[' CustomersActive ','Active ']]
然后下面的内容会让你得到你想要的

data_NameExtracted = [x[0].strip() for x in data]

不能将其放入lambda表达式中,但可以使用以下生成器对象:

# please note that i have used tuples instead of sets, 
# because sets are unordered
data = [
    (' Customers ','null,blank '),
    (' CustomersName ','max=50,null,blank '), 
    (' CustomersAddress ','max=150,blank '),
    (' CustomersActive ','Active ')
]

# Indexing is not allowed for set objects
values = [item[0].strip() for item in data]
data = [
    {' Customers ': 'null,blank '},
    {' CustomersName ': 'max=50,null,blank '}, 
    {' CustomersAddress ': 'max=150,blank '},
    {' CustomersActive ': 'Active '}
]
# expecting a single value in the dicts
values = [item.values()[0].strip() for item in data]
见:

编辑:

如果您不想使用字典,您可以使用以下内容:

# please note that i have used tuples instead of sets, 
# because sets are unordered
data = [
    (' Customers ','null,blank '),
    (' CustomersName ','max=50,null,blank '), 
    (' CustomersAddress ','max=150,blank '),
    (' CustomersActive ','Active ')
]

# Indexing is not allowed for set objects
values = [item[0].strip() for item in data]
data = [
    {' Customers ': 'null,blank '},
    {' CustomersName ': 'max=50,null,blank '}, 
    {' CustomersAddress ': 'max=150,blank '},
    {' CustomersActive ': 'Active '}
]
# expecting a single value in the dicts
values = [item.values()[0].strip() for item in data]