from itertools import islice
def infinite_seq():
n = 1
while True:
yield n
n *= 2
gen = infinite_seq()
result = list(islice(gen, 5))
print(sum(result))
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
x = [1, 2]
def f():
x += [3]
try:
f()
except UnboundLocalError:
print("Error")
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
for i in range(3):
if i == 5:
break
else:
print("A", end="")
print("B", end="")
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
d = {'a': 1, 'b': 2, 'c': 3}
try:
for k in d:
del d[k]
print(len(d))
except RuntimeError:
print("RuntimeError")#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
class Context:
def __enter__(self):
return "A"
def __exit__(self, *args):
return True
with Context() as c:
raise ValueError()
print(c)
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM