0

I have something from 2.4 and i'd like to convert it for 2.7 but the problem is, i crash everytime at this string:

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

is there a counterpart to

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

for 2.7?

Here is the part of the code itself:

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

3 Answers3

3

1)The bracket ( does not close at the end.

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

2) Variables should not contain hyphens (outmost-iterable).

3) No operation is done while iterating through the for loop.

for x in [outmost-iterable]

should be something like

x for x in [outmost-iterable]

4) Not sure if you really want to use [ ]. Doing so you're iterating through only one element.

a = [1,2,3]
b = [x for x in [a]] # b = [[1,2,3]]
c = [x for x in a]   # c = [1,2,3]
Ashoka Lella
  • 6,631
  • 1
  • 30
  • 39
  • It will give you error `>>> MovieCasts = tuple(lambda [outmost-iterable]: for x in [outmost-iterable]) File "", line 1 MovieCasts = tuple(lambda [outmost-iterable]: for x in [outmost-iterable]) ^ SyntaxError: invalid syntax` – Nilesh Jul 03 '14 at 07:02
0

You have to close tuple (. Please correct the text.

You can achieve convert data to tuple as.

MovieCasts = tuple(lambda outmost_iterable: x for x in range(10))
Nilesh
  • 20,521
  • 16
  • 92
  • 148
0
def tup(a): return tuple(i for i in a)

or

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

for your code

tuple([outmost-iterable])

i think there is no need of using lambda

sundar nataraj
  • 8,524
  • 2
  • 34
  • 46