Skip to content

Instantly share code, notes, and snippets.

@dskecse
Last active November 25, 2023 10:16
Show Gist options
  • Save dskecse/c7e9fd3495b3126d061c08d074700816 to your computer and use it in GitHub Desktop.
Save dskecse/c7e9fd3495b3126d061c08d074700816 to your computer and use it in GitHub Desktop.
Python dict magic to Ruby
matches = dict(['()', '[]', '{}'])
print(matches)
# {'(': ')', '[': ']', '{': '}'}
Hash[['()'.split('')]]
# {"("=>")"}
['()'.split('')]
# [["(", ")"]]
Hash[ [["(", ")"], ["[", "]"]] ]
# {"("=>")", "["=>"]"}
['()', '[]', '{}'].map { _1.split('') }
# [["(", ")"], ["[", "]"], ["{", "}"]]
matches = Hash[['()', '[]', '{}'].map { _1.split('') }]
# {"("=>")", "["=>"]", "{"=>"}"}
matches = ['()', '[]', '{}'].map { _1.split('') }.to_h
# {"("=>")", "["=>"]", "{"=>"}"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment