0

In python if you have a nested dictionary, accessing elements will look like this:

dict["key1"]["key2"]

How would I go about swapping the two keys the fastest? Nothing really comes to my mind other than something like di[wwdi["p1bbp.

Also just out of curiosity, if the construct is dict.key1.key2 are there different/better solutions?

1 Answer 1

3

What comes to my mind is

da[%p

Using % is less important. Just make sure to cut the whole [expr] and put it back where appropriate.

if the construct is dict.key1.key2

Something like moving to the left dot then cutting the key with dt.. And then ep or something like that to put it back. If you have a plugin like wellle/targets then you can cut it with da. instead.

1
  • I have no idea why I didn't think of just cutting the entire expression ... :D Very easy and fast, thanks!
    – fbence
    Jun 30, 2022 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.