4 ms·
Great article. I use unpacking regularly for a lot of the reasons given, as it helps ensure data is in its expected shape. However, I never knew of "star assign
by z3c0 4y ago
Great article. I use unpacking regularly for a lot of the reasons given, as it helps ensure data is in its expected shape. However, I never knew of "star assignment" eg
first, second, *others = some_tuple
I've opted for less-readable positional indexing several times for not realizing this. Looks like I have some updates to do.
- JadeNB 4y ago> However, I never knew of "star assignment" eg first, second, *others = some_tuple For what it's worth, I think that's often called "splat".
- delaaxe 4y agoYou can also do: first, second, *_ = some_tuple If you don't care about the others
- jwarden 4y agoThis reminds me of an idea I wrote about years ago called Pass-Through Lists, where every assignment is implicitly a destructuring assignment: https://jonathanwarden.com/2014/06/19/pass-through-lists/ https://jonathanwarden.com/2014/06/19/pass-through-lists/