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?

fbence
  • 677
  • 4
  • 12

1 Answers1

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.

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