File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Invert Dictionary 2
2
+
3
+ Another way to switch the key-value pairs of a dictionary.
4
+
5
+ ## Before
6
+
7
+ ``` gdscript
8
+ var color_to_points = {
9
+ "red" = 0,
10
+ "orange" = 5,
11
+ "yellow" = 10,
12
+ "green" = 15,
13
+ "blue" = 20,
14
+ "purple" = 30,
15
+ "black" = 50,
16
+ }
17
+ ```
18
+
19
+ ## After
20
+
21
+ ``` gdscript
22
+ var points_to_color = {
23
+ 0 = "red",
24
+ 5 = "orange",
25
+ 10 = "yellow",
26
+ 15 = "green",
27
+ 20 = "blue",
28
+ 30 = "purple",
29
+ 50 = "black",
30
+ }
31
+ ```
32
+
33
+ ## Command
34
+
35
+ ```
36
+ webS_to_<enter><alt-(>
37
+
38
+ xt}S,|=<enter>_2<alt-(>
39
+ ```
40
+
41
+ 1 . ` web ` selects the second word without whitespace
42
+ 1 . ` S ` splits the selection on regex match. We type in ` _to_ ` for the regex and hit ` <enter> ` to split it into two sections
43
+ 1 . ` <alt-(> ` rotates the contents of the selections
44
+ 1 . ` x ` selects the whole line
45
+ 1 . ` t} ` selects until (but not including) the next "}" character
46
+ 1 . ` S ` splits the selection on regex match. We type in ` ,|= ` for the regex and hit ` <enter> ` to split it into sub-selections
47
+ 1 . ` _ ` trims trailing whitespace on all selections
48
+ 1 . ` 2<alt-(> ` rotates the contents of selections, but only between pairs of selections.
You can’t perform that action at this time.
0 commit comments