Named stores (PyNamespace: dotted access, functions that see their own store first, restored after a
save is loaded), real generators run step by step (next, send, yield as an expression), len/bool through
__len__/__bool__, os/calendar/itertools/pygame_sdl2 helpers, Skip and ToggleLocalVariable actions,
text tags {glitch} and {wave} and plain display of explode/gradient/ruby, SnowBlossom and anim.Blink,
RoundedCorners as a transform, transforms listed in `at`, ATL choice weights that are flags, and
renpy.image_size from the converter's picture sizes.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
64 lines
1.2 KiB
Python
64 lines
1.2 KiB
Python
class Perk:
|
|
def __init__(self, key):
|
|
self.key = key
|
|
|
|
def __hash__(self):
|
|
return hash(self.key)
|
|
|
|
def __eq__(self, other):
|
|
return self.key == other.key
|
|
|
|
|
|
class Bag:
|
|
def __init__(self, items):
|
|
self.items = items
|
|
|
|
def __iter__(self):
|
|
return iter(self.items)
|
|
|
|
def __getitem__(self, i):
|
|
return self.items[i]
|
|
|
|
def __contains__(self, x):
|
|
return x in self.items
|
|
|
|
|
|
table = {}
|
|
table[Perk("a")] = 1
|
|
table[Perk("a")] = 2
|
|
result_size = len(table)
|
|
result_value = table[Perk("a")]
|
|
bag = Bag([3, 4, 5])
|
|
result_loop = [x * 2 for x in bag]
|
|
result_item = bag[1]
|
|
result_in = 4 in bag
|
|
result_out = 9 in bag
|
|
|
|
|
|
def walk(values, kind):
|
|
seen = []
|
|
for value in values:
|
|
if isinstance(value, kind):
|
|
yield value
|
|
elif isinstance(value, list):
|
|
yield from walk(value, kind)
|
|
|
|
|
|
result_found = list(walk([1, "a", [2, "b", [3]], 4], int))
|
|
result_iter = iter([7, 8])
|
|
result_first = next(result_iter)
|
|
result_second = next(result_iter)
|
|
result_default = next(result_iter, "done")
|
|
|
|
|
|
def coro():
|
|
got = yield 1
|
|
other = yield got + 1
|
|
yield other * 2
|
|
|
|
|
|
g = coro()
|
|
result_a = next(g)
|
|
result_b = g.send(10)
|
|
result_c = g.send(5)
|