cut
stringclasses
1 value
version
stringclasses
10 values
idiom_id
stringclasses
53 values
pep
stringclasses
53 values
introduced_in
stringclasses
11 values
form
stringclasses
2 values
file
stringclasses
887 values
code
stringclasses
916 values
source
stringclasses
1 value
origin
stringlengths
15
17
origin_revision
stringclasses
10 values
license
stringclasses
1 value
train
3.15
fstring
498
3.6
modern
fstring/modern_16.py
for x in (32, 100, 'fifty'): print(f'x = {x:+3}')
pydocs
pep-0498.rst:422
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_17.py
def fn(l, incr): result = l[0] l[0] += incr return result lst = [0] f'{fn(lst,2)} {fn(lst,3)}' f'{fn(lst,2)} {fn(lst,3)}' lst
pydocs
pep-0498.rst:444
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_18.py
f'Column={col_idx+1}' f'number of items: {len(items)}'
pydocs
pep-0498.rst:518
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_19.py
col_number = col_idx+1 f'Column={col_number}' n_items = len(items) f'number of items: {n_items}'
pydocs
pep-0498.rst:523
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_20.py
f'mapping is { {a:b for (a, b) in ((1, 2), (3, 4))} }'
pydocs
pep-0498.rst:532
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
legacy
fstring/legacy_08.py
d = {'a': 10, 'b': 20} 'a={d[a]}'.format(d=d)
pydocs
pep-0498.rst:551
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_21.py
f'a={d["a"]}'
pydocs
pep-0498.rst:561
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_22.py
a = 'b' f'a={d[a]}'
pydocs
pep-0498.rst:567
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
legacy
fstring/legacy_09.py
'{i[";]}'.format(i={'";':4})
pydocs
pep-0498.rst:577
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_23.py
header = 'Subject' fr'{header}:\s+'
pydocs
pep-0498.rst:597
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_24.py
a = 'some string' f'{a!r}'
pydocs
pep-0498.rst:632
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_25.py
f'{repr(a)}'
pydocs
pep-0498.rst:638
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_26.py
f'{(lambda x: x*2)(3)}'
pydocs
pep-0498.rst:661
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_27.py
extra = '{},waiters:{}'.format(extra, len(self._waiters)) extra = f'{extra},waiters:{len(self._waiters)}'
pydocs
pep-0498.rst:683
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_28.py
message.append(" [line {0:2d}]".format(lineno)) message.append(f" [line {lineno:2d}]")
pydocs
pep-0498.rst:688
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_29.py
methoddef_name = "{}_METHODDEF".format(c_basename.upper()) methoddef_name = f"{c_basename.upper()}_METHODDEF"
pydocs
pep-0498.rst:693
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
fstring
498
3.6
modern
fstring/modern_30.py
print("Usage: {0} [{1}]".format(sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr) print(f"Usage: {sys.argv[0]} [{'|'.join('--'+opt for opt in valid_opts)}]", file=sys.stderr)
pydocs
pep-0498.rst:698
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_01.py
match = re.match(data) group = match.group(1) if match else None
pydocs
pep-0572.rst:86
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_02.py
group = re.match(data).group(1) if re.match(data) else None
pydocs
pep-0572.rst:91
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_03.py
match1 = pattern1.match(data) match2 = pattern2.match(data) if match1: result = match1.group(1) elif match2: result = match2.group(2) else: result = None
pydocs
pep-0572.rst:96
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_04.py
match1 = pattern1.match(data) if match1: result = match1.group(1) else: match2 = pattern2.match(data) if match2: result = match2.group(2) else: result = None
pydocs
pep-0572.rst:109
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_01.py
# Handle a matched regex if (match := pattern.search(data)) is not None: ... # Do something with match # A loop that can't be trivially rewritten using 2-arg iter() while chunk := file.read(8192): process(chunk) # Reuse a value that's expensive to compute [y := f(x), y**2, y**3] # Share a subexpression be...
pydocs
pep-0572.rst:132
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_02.py
f'{(x:=10)}' # Valid, uses assignment expression x = 10 f'{x:=10}' # Valid, passes '=10' to formatter
pydocs
pep-0572.rst:221
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_03.py
if any((comment := line).startswith('#') for line in lines): print("First comment:", comment) else: print("There are no comments") if all((nonblank := line).strip() == '' for line in lines): print("All lines are blank") else: print("First non-blank line:", nonblank)
pydocs
pep-0572.rst:256
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_04.py
# Compute partial sums in a list comprehension total = 0 partial_sums = [total := total + v for v in values] print("Total:", total)
pydocs
pep-0572.rst:269
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_05.py
[[(j := j) for i in range(5)] for j in range(5)] # INVALID [i := 0 for i, j in stuff] # INVALID [i+1 for i in (i := stuff)] # INVALID
pydocs
pep-0572.rst:286
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_06.py
[False and (i := 0) for i, j in stuff] # INVALID [i for i, j in stuff if True or (j := 1)] # INVALID
pydocs
pep-0572.rst:298
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_07.py
[i+1 for i in (j := stuff)] # INVALID [i+1 for i in range(2) for j in (k := stuff)] # INVALID [i+1 for i in [j for j in (k := stuff)]] # INVALID [i+1 for i in (lambda: (j := stuff))()] # INVALID
pydocs
pep-0572.rst:315
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_08.py
class Example: [(j := i) for i in range(5)] # INVALID
pydocs
pep-0572.rst:326
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_09.py
# Valid if any(len(longline := line) >= 100 for line in lines): print("Extremely long line:", longline)
pydocs
pep-0572.rst:385
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_10.py
x = 1, 2 # Sets x to (1, 2) (x := 1, 2) # Sets x to 1
pydocs
pep-0572.rst:432
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_05.py
env_base = os.environ.get("PYTHONUSERBASE", None) if env_base: return env_base
pydocs
pep-0572.rst:490
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_11.py
if env_base := os.environ.get("PYTHONUSERBASE", None): return env_base
pydocs
pep-0572.rst:496
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_06.py
if self._is_special: ans = self._check_nans(context=context) if ans: return ans
pydocs
pep-0572.rst:506
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_12.py
if self._is_special and (ans := self._check_nans(context=context)): return ans
pydocs
pep-0572.rst:513
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_07.py
reductor = dispatch_table.get(cls) if reductor: rv = reductor(x) else: reductor = getattr(x, "__reduce_ex__", None) if reductor: rv = reductor(4) else: reductor = getattr(x, "__reduce__", None) if reductor: rv = reductor() else: raise Error( ...
pydocs
pep-0572.rst:524
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_13.py
if reductor := dispatch_table.get(cls): rv = reductor(x) elif reductor := getattr(x, "__reduce_ex__", None): rv = reductor(4) elif reductor := getattr(x, "__reduce__", None): rv = reductor() else: raise Error("un(deep)copyable object of type %s" % cls)
pydocs
pep-0572.rst:541
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_08.py
s = _format_time(self._hour, self._minute, self._second, self._microsecond, timespec) tz = self._tzstr() if tz: s += tz return s
pydocs
pep-0572.rst:558
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_14.py
s = _format_time(self._hour, self._minute, self._second, self._microsecond, timespec) if tz := self._tzstr(): s += tz return s
pydocs
pep-0572.rst:568
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_09.py
while True: line = fp.readline() if not line: break m = define_rx.match(line) if m: n, v = m.group(1, 2) try: v = int(v) except ValueError: pass vars[n] = v else: m = undef_rx.match(line) if m: vars[m.group(1...
pydocs
pep-0572.rst:584
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_15.py
while line := fp.readline(): if m := define_rx.match(line): n, v = m.group(1, 2) try: v = int(v) except ValueError: pass vars[n] = v elif m := undef_rx.match(line): vars[m.group(1)] = 0
pydocs
pep-0572.rst:603
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_16.py
results = [(x, y, x/y) for x in input_data if (y := f(x)) > 0]
pydocs
pep-0572.rst:621
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_17.py
stuff = [[y := f(x), x/y] for x in range(5)]
pydocs
pep-0572.rst:626
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_18.py
# Loop-and-a-half while (command := input("> ")) != "quit": print("You entered:", command) # Capturing regular expression match objects # See, for instance, Lib/pydoc.py, which uses a multiline spelling # of this effect if match := re.search(pat, text): print("Found:", match.group(0)) # The same syntax chains ...
pydocs
pep-0572.rst:638
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_19.py
if pid := os.fork(): ... # Parent code else: ... # Child code
pydocs
pep-0572.rst:668
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_20.py
pos = -1 while pos := buffer.find(search_term, pos + 1) >= 0: ...
pydocs
pep-0572.rst:861
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_21.py
(point := (x, y)) (point := x, y)
pydocs
pep-0572.rst:881
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_22.py
foo(x := 1, y) foo(x := (1, y))
pydocs
pep-0572.rst:891
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_23.py
# Top level in if if match := pattern.match(line): return match.group(1) # Short call len(lines := f.readlines())
pydocs
pep-0572.rst:906
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_10.py
mylast = mylast[1] yield mylast[0]
pydocs
pep-0572.rst:995
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_24.py
yield (mylast := mylast[1])[0]
pydocs
pep-0572.rst:1000
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_11.py
while True: old = total total += term if old == total: return total term *= mx2 / (i*(i+1)) i += 2
pydocs
pep-0572.rst:1008
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_25.py
while total != (total := total + term): term *= mx2 / (i*(i+1)) i += 2 return total
pydocs
pep-0572.rst:1018
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_12.py
result = solution(xs, n) if result: ... # use result
pydocs
pep-0572.rst:1036
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_26.py
if result := solution(xs, n): ... # use result
pydocs
pep-0572.rst:1043
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_13.py
reductor = dispatch_table.get(cls) if reductor: rv = reductor(x) else: reductor = getattr(x, "__reduce_ex__", None) if reductor: rv = reductor(4) else: reductor = getattr(x, "__reduce__", None) if reductor: rv = reductor() else: raise Error("un(sha...
pydocs
pep-0572.rst:1056
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_27.py
if reductor := dispatch_table.get(cls): rv = reductor(x) elif reductor := getattr(x, "__reduce_ex__", None): rv = reductor(4) elif reductor := getattr(x, "__reduce__", None): rv = reductor() else: raise Error("un(shallow)copyable object of type %s" % cls)
pydocs
pep-0572.rst:1073
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_14.py
diff = x - x_base if diff: g = gcd(diff, n) if g > 1: return g
pydocs
pep-0572.rst:1090
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_28.py
if (diff := x - x_base) and (g := gcd(diff, n)) > 1: return g
pydocs
pep-0572.rst:1098
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_29.py
while a > (d := x // a**(n-1)): a = ((n-1)*a + d) // n return a
pydocs
pep-0572.rst:1121
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
legacy
walrus/legacy_15.py
while True: d = x // a**(n-1) if a <= d: break a = ((n-1)*a + d) // n return a
pydocs
pep-0572.rst:1139
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_30.py
def f(): a = [TARGET := EXPR for VAR in ITERABLE]
pydocs
pep-0572.rst:1191
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_31.py
def f(): global TARGET a = [TARGET := EXPR for VAR in ITERABLE]
pydocs
pep-0572.rst:1210
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_32.py
def g(): TARGET = ... def f(): nonlocal TARGET a = [TARGET := EXPR for VAR in ITERABLE]
pydocs
pep-0572.rst:1229
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_33.py
def f(): a = [[TARGET := i for i in range(3)] for j in range(2)] # I.e., a = [[0, 1, 2], [0, 1, 2]] print(TARGET) # prints 2
pydocs
pep-0572.rst:1252
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
walrus
572
3.8
modern
walrus/modern_34.py
a = 42 def f(): # `a` is local to `f`, but remains unbound # until the caller executes this genexp: yield ((a := i) for i in range(3)) yield lambda: a + 100 print("done") try: print(f"`a` is bound to {a}") assert False except UnboundLocalError: print("`a` is not yet b...
pydocs
pep-0572.rst:1283
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_01.py
match command.split(): case [action, obj]: ... # interpret action, obj
pydocs
pep-0636.rst:63
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_02.py
match command.split(): case [action]: ... # interpret single-verb action case [action, obj]: ... # interpret action, obj
pydocs
pep-0636.rst:94
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_03.py
match command.split(): case ["quit"]: print("Goodbye!") quit_game() case ["look"]: current_room.describe() case ["get", obj]: character.get(obj, current_room) case ["go", direction]: current_room = current_room.neighbor(direction) # The rest of your commands g...
pydocs
pep-0636.rst:116
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_04.py
match command.split(): case ["drop", *objects]: for obj in objects: character.drop(obj, current_room) # The rest of your commands go here
pydocs
pep-0636.rst:147
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_05.py
match command.split(): case ["go", ("north" | "south" | "east" | "west")]: current_room = current_room.neighbor(...) # how do I know which direction to go?
pydocs
pep-0636.rst:245
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_06.py
match command.split(): case ["go", ("north" | "south" | "east" | "west") as direction]: current_room = current_room.neighbor(direction)
pydocs
pep-0636.rst:255
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_07.py
match command.split(): case ["go", direction] if direction in current_room.exits: current_room = current_room.neighbor(direction) case ["go", _]: print("Sorry, you can't go that way")
pydocs
pep-0636.rst:271
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_08.py
match event.get(): case Click((x, y)): handle_click_at(x, y)
pydocs
pep-0636.rst:344
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_09.py
match event.get(): case Click((x, y), button=Button.LEFT): # This is a left click handle_click_at(x, y) case Click(): pass # ignore other clicks
pydocs
pep-0636.rst:375
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_10.py
for action in actions: match action: case {"text": message, "color": c}: ui.set_text_color(c) ui.display(message) case {"sleep": duration}: ui.wait(duration) case {"sound": url, "format": "ogg"}: ui.play(url) case {"sound": _, "format":...
pydocs
pep-0636.rst:403
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_11.py
for action in actions: match action: case {"text": str(message), "color": str(c)}: ui.set_text_color(c) ui.display(message) case {"sleep": float(duration)}: ui.wait(duration) case {"sound": str(url), "format": "ogg"}: ui.play(url) case ...
pydocs
pep-0636.rst:439
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_12.py
def http_error(status): match status: case 400: return "Bad request" case 404: return "Not found" case 418: return "I'm a teapot" case _: return "Something's wrong with the Internet"
pydocs
pep-0636.rst:465
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_13.py
# point is an (x, y) tuple match point: case (0, 0): print("Origin") case (0, y): print(f"Y={y}") case (x, 0): print(f"X={x}") case (x, y): print(f"X={x}, Y={y}") case _: raise ValueError("Not a point")
pydocs
pep-0636.rst:487
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_14.py
from dataclasses import dataclass @dataclass class Point: x: int y: int def where_is(point): match point: case Point(x=0, y=0): print("Origin") case Point(x=0, y=y): print(f"Y={y}") case Point(x=x, y=0): print(f"X={x}") case Point(): ...
pydocs
pep-0636.rst:511
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_15.py
match points: case []: print("No points") case [Point(0, 0)]: print("The origin") case [Point(x, y)]: print(f"Single point {x}, {y}") case [Point(0, y1), Point(0, y2)]: print(f"Two on the Y axis at {y1}, {y2}") case _: print("Something else")
pydocs
pep-0636.rst:545
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_16.py
match point: case Point(x, y) if x == y: print(f"Y=X at {x}") case Point(x, y): print(f"Not on the diagonal")
pydocs
pep-0636.rst:561
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
pattern-matching
634
3.10
modern
pattern-matching/modern_17.py
from enum import Enum class Color(Enum): RED = 0 GREEN = 1 BLUE = 2 match color: case Color.RED: print("I see red!") case Color.GREEN: print("Grass is green") case Color.BLUE: print("I'm feeling the blues :(")
pydocs
pep-0636.rst:595
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
legacy
dict-union/legacy_01.py
d1 = {'spam': 1} d2 = {'eggs': 2} merged = ChainMap(d2, d1) merged['eggs'] = 999 d2
pydocs
pep-0584.rst:80
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
legacy
dict-union/legacy_02.py
d1 = {"spam": 1} d2 = {3665: 2} dict(d1, **d2)
pydocs
pep-0584.rst:95
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
legacy
dict-union/legacy_03.py
{'a': 1, 'a': 2} {**d, **e} d.update(e) d[k] = v {k: v for x in (d, e) for (k, v) in x.items()}
pydocs
pep-0584.rst:121
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_01.py
d = {'spam': 1, 'eggs': 2, 'cheese': 3} e = {'cheese': 'cheddar', 'aardvark': 'Ethel'} d | e e | d
pydocs
pep-0584.rst:147
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_02.py
d |= e d
pydocs
pep-0584.rst:156
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_03.py
d | [('spam', 999)] d |= [('spam', 999)] d
pydocs
pep-0584.rst:167
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_04.py
new = {} for d in many_dicts: new |= d
pydocs
pep-0584.rst:267
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_05.py
flags |= WRITEABLE # Probably numeric bitwise-or. DO_NOT_RUN = WEEKENDS | HOLIDAYS # Probably set union. settings = DEFAULT_SETTINGS | user_settings | workspace_settings # Probably dict union.
pydocs
pep-0584.rst:385
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_06.py
d2 | d1 # d1 merged with d2, keeping existing values in d1
pydocs
pep-0584.rst:488
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_07.py
{'a': [1, 2]} | {'a': [3, 4]}
pydocs
pep-0584.rst:498
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
legacy
dict-union/legacy_04.py
aliases = dict(kernel_aliases) aliases.update(shell_aliases)
pydocs
pep-0584.rst:667
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_08.py
aliases = kernel_aliases | shell_aliases
pydocs
pep-0584.rst:672
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
legacy
dict-union/legacy_05.py
kernel_aliases = dict(base_aliases) kernel_aliases.update({ 'ip' : 'KernelApp.ip', 'hb' : 'KernelApp.hb_port', 'shell' : 'KernelApp.shell_port', 'iopub' : 'KernelApp.iopub_port', 'stdin' : 'KernelApp.stdin_port', 'parent': 'KernelApp.parent', }) if sys.platform.startswith('win'): kernel_alia...
pydocs
pep-0584.rst:681
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_09.py
kernel_aliases = base_aliases | { 'ip' : 'KernelApp.ip', 'hb' : 'KernelApp.hb_port', 'shell' : 'KernelApp.shell_port', 'iopub' : 'KernelApp.iopub_port', 'stdin' : 'KernelApp.stdin_port', 'parent': 'KernelApp.parent', } if sys.platform.startswith('win'): kernel_aliases['interrupt'] = 'KernelA...
pydocs
pep-0584.rst:705
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
legacy
dict-union/legacy_06.py
attrib = attrib.copy() attrib.update(extra) attrib = attrib.items()
pydocs
pep-0584.rst:732
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
modern
dict-union/modern_10.py
attrib = (attrib | extra).items()
pydocs
pep-0584.rst:738
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0
train
3.15
dict-union
584
3.9
legacy
dict-union/legacy_07.py
edges = {} edges.update(dict(zip(self.triangle_nodes[border[:,0]][:,1], self.triangle_nodes[border[:,0]][:,2]))) edges.update(dict(zip(self.triangle_nodes[border[:,1]][:,2], self.triangle_nodes[border[:,1]][:,0]))) edges.update(dict(zip(self.triangle_nodes[border[:,2]][:,0], self....
pydocs
pep-0584.rst:747
e449c7e446faec3ecf953e83fbe677b771bf5d7c
CC0-1.0