-2

I wrote this expression

[0 for j in range(4)]

and python accepted it as definition of list, but when i wrote this expression:

0 for j in range(4)

it raises an error.

what is mechanism of that and from which language does it origin? is it from functional programming ie. LISP? What is equivalent in Java or C?

EDIT: the difference from answered question is that there is not left part of equitation, just right part

[code]

Also I was interested in origin of list comprehension and equivalents in other programming languages.

user1406647
  • 489
  • 1
  • 5
  • 17

1 Answers1

2

[0 for j in range(4)] is a list comprehension. This is perfectly valid Python syntax.

The other expression isn't an expression at all.

Makoto
  • 104,088
  • 27
  • 192
  • 230