2 ms·
This confuses me a bit dct = {'a': [1, 2, 3]} {'a': [1, *rest]} = dct print(rest) # [2, 3] Does this mean that i can use? dct = {'a': [1, 2, 3]} {
by qwertox 1y ago
This confuses me a bit
dct = {'a': [1, 2, 3]}
{'a': [1, *rest]} = dct
print(rest) # [2, 3]
Does this mean that i can use?
dct = {'a': [1, 2, 3]}
{'b': [4, *rest]} = dct
print(rest) # [2, 3]
and more explicit
dct = {'a': [1, 2, 3]}
{'_': [_, *rest]} = dct
print(rest) # [2, 3]
- qexat 1y agoNone of the last two LHSes will match `dct`, so you'll get a runtime error.
- masklinn 1y ago> Does this mean that i can use? They'll both trigger a runtime error, since the key you're using in the pattern (LHS) does not match any key in the dict. Note that `'_'` is an actual string, and thus key, it's not any sort of wildcard. Using a bare `_` as key yields a syntax error, I assume because it's too ambiguous for the author to want to support it.