Skip to main content
deleted 6 characters in body
Source Link
Tolli
  • 131
  • 3
for i in iter(lambda : 0, 1): 
    print (i) # prints 0 forever 

The iter function is normally used to create an iterator from an iterable.

The iter function can also take two arguments, a callable and a sentinel value. In that case it returns an iterator that yields the result of the callable until the callable returns the sentinel value.

In this case, the callable is a lambda that always returns 0. Since it never can return the sentinel value (1), this will loop forever.

Since this is code golf, this version comes is 28 characters and only one line:

for i in iter(lambda:0,1):i
for i in iter(lambda : 0, 1): 
    print (i) # prints 0 forever 

The iter function is normally used to create an iterator from an iterable.

The iter function can also take two arguments, a callable and a sentinel value. In that case it returns an iterator that yields the result of the callable until the callable returns the sentinel value.

In this case, the callable is a lambda that always returns 0. Since it never can return the sentinel value (1), this will loop forever.

Since this is code golf, this version comes is 28 characters and only one line:

for i in iter(lambda:0,1):i
for i in iter(lambda : 0, 1): 
    print (i) # prints 0 forever 

The iter function is normally used to create an iterator from an iterable.

The iter function can also take two arguments, a callable and a sentinel value. In that case it returns an iterator that yields the result of the callable until the callable returns the sentinel value.

In this case, the callable is a lambda that always returns 0. Since it never can return the sentinel value (1), this will loop forever.

Since this is code golf, this version is 28 characters and only one line:

for i in iter(lambda:0,1):i
added 118 characters in body
Source Link
Tolli
  • 131
  • 3
for i in iter(lambda : 0, 1): 
    print (i) # prints 0 forever 

The iter function is normally used to create an iterator from an iterable.

The iter function can also take two arguments, a callable and a sentinel value. In that case it returns an iterator that yields the result of the callable until the callable returns the sentinel value.

In this case, the callable is a lambda that always returns 0. Since it never can return the sentinel value (1), this will loop forever.

Since this is code golf, this version comes is 28 characters and only one line:

for i in iter(lambda:0,1):i
for i in iter(lambda : 0, 1): 
    print (i) # prints 0 forever 

The iter function is normally used to create an iterator from an iterable.

The iter function can also take two arguments, a callable and a sentinel value. In that case it returns an iterator that yields the result of the callable until the callable returns the sentinel value.

In this case, the callable is a lambda that always returns 0. Since it never can return the sentinel value (1), this will loop forever.

for i in iter(lambda : 0, 1): 
    print (i) # prints 0 forever 

The iter function is normally used to create an iterator from an iterable.

The iter function can also take two arguments, a callable and a sentinel value. In that case it returns an iterator that yields the result of the callable until the callable returns the sentinel value.

In this case, the callable is a lambda that always returns 0. Since it never can return the sentinel value (1), this will loop forever.

Since this is code golf, this version comes is 28 characters and only one line:

for i in iter(lambda:0,1):i
Source Link
Tolli
  • 131
  • 3

for i in iter(lambda : 0, 1): 
    print (i) # prints 0 forever 

The iter function is normally used to create an iterator from an iterable.

The iter function can also take two arguments, a callable and a sentinel value. In that case it returns an iterator that yields the result of the callable until the callable returns the sentinel value.

In this case, the callable is a lambda that always returns 0. Since it never can return the sentinel value (1), this will loop forever.