Please open Telegram to view this post
VIEW IN TELEGRAM
for i in range(2):
try:
print(i, end="")
continue
finally:
print("F", end="")
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
colors = ['red', 'green', 'blue']
colors.insert(1, colors.pop())
colors.reverse()
print(colors[0])
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
data = {}
data.setdefault("keys", []).append(1)
data.setdefault("keys", []).append(2)
print(data["keys"])#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
This media is not supported in your browser
VIEW IN TELEGRAM
Вот 14 авторских обучающих IT каналов по самым востребованным областям программирования:
Выбирай своё направление:
Please open Telegram to view this post
VIEW IN TELEGRAM
def make_counter():
count = 0
def increment():
nonlocal count
count += 1
return count
return increment
c1 = make_counter()
c2 = make_counter()
c1()
print(c1(), c2())
#Python
Please open Telegram to view this post
VIEW IN TELEGRAM
from collections import defaultdict
class Tree(defaultdict):
def __init__(self):
super().__init__(Tree)
t = Tree()
t['a']['b']['c'] = 10
t['a']['b']['d'] = 20
t['a']['e'] = 5
def count_leaves(d):
total = 0
for v in d.values():
if isinstance(v, dict):
total += count_leaves(v)
else:
total += v
return total
print(count_leaves(t))
#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
👍1