0

我有 2.4 的东西,我想将它转换为 2.7,但问题是,我每次都在这个字符串上崩溃:

MovieCasts = tuple(lambda [outmost-iterable]: for x in [outmost-iterable]:
SyntaxError: invalid syntax

有没有对应的

tuple(lambda [outmost-iterable]: for x in [outmost-iterable]:

2.7?

这是代码本身的一部分:

MovieCasts = tuple(lambda [outmost-iterable]: for x in [outmost-iterable]):
AvatarType()(range(6)))
4

3 回答 3

3

1) 支架(最后没有闭合。

MovieCasts = tuple(lambda [outmost-iterable]: for x in [outmost-iterable]:
                  ^                                                       ^

2) 变量不应包含连字符 ( outmost-iterable)。

3) 遍历 for 循环时不进行任何操作。

for x in [outmost-iterable]

应该是这样的

x for x in [outmost-iterable]

4)不确定你是否真的想使用[ ]. 这样做你只迭代一个元素。

a = [1,2,3]
b = [x for x in [a]] # b = [[1,2,3]]
c = [x for x in a]   # c = [1,2,3]
于 2014-07-03T06:50:48.120 回答
0

你必须关闭 tuple (。请更正文字。

您可以实现将数据转换为元组。

MovieCasts = tuple(lambda outmost_iterable: x for x in range(10))
于 2014-07-03T06:53:39.957 回答
0
def tup(a): return tuple(i for i in a)

或者

def tup(a): return tuple(a)
print tup(range(10))
#output (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

为您的代码

tuple([outmost-iterable])

我认为没有必要使用 lambda

于 2014-07-03T06:58:39.827 回答