Skip to content

Commit

Permalink
docs: add python snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
niekdt committed Sep 27, 2024
1 parent 540df7c commit cddb7b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/actionsheets/data/python/collections/dict.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ code = "next(k for k in x if x[k] == v)"
action = "All keys with value _v_"
code = "[k for k in x if x[k] == v]"

[extract.index.key]
action = "Get index of key _k_"
code = "list(x.keys()).index(k)"


[update]
section = "Update"
Expand Down
14 changes: 14 additions & 0 deletions src/actionsheets/data/python/collections/list.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ code = "x[0]"
action = "Last element"
code = "x[-1]"

[extract.elem.sample]
action = "Random element"
code = """
import random
random.choice(x)
"""

[extract.elem.count]
action = "Number of occurrences of element"
code = "x.count(e)"
Expand Down Expand Up @@ -470,6 +477,13 @@ code = "x[:n]"
action = "Last _n_ elements (tail)"
code = "x[-n:]"

[derive.shrink.sample]
action = "Select _n_ elements at random"
code = """
import random
random.choices(x, k=n)
"""

[derive.shrink.indices]
action = "List of elements from a list of indices"
code = "[x[i] for i in indices]"
Expand Down

0 comments on commit cddb7b9

Please sign in to comment.