Created
October 1, 2019 00:32
-
-
Save FrancoB411/b4aa87dd503c84f7315d26f38d491572 to your computer and use it in GitHub Desktop.
ohms regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
re_string = "(\d+\.\d+|\d+|)(\D*)\s(ohms)" | |
inputs = [ | |
"10 ohms", | |
"100 ohms", | |
"220 ohms", | |
"330 ohms", | |
"470 ohms", | |
"680 ohms", | |
"1k ohms", | |
"10k ohms", | |
"22k ohms", | |
"47k ohms", | |
"4.7k ohms", | |
"100k ohms", | |
"330k ohms", | |
"2M ohms" | |
] | |
for input in inputs: | |
i = re.search(re_string, input) | |
print(i.group(1)) | |
print(i.group(2)) | |
print(i.group(3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def encode_resistor_colors(ohms_string):
color_codes = {"0": "black",
"1": "brown",
"2": "red",
"3": "orange",
"4": "yellow",
"5": "green",
"6": "blue",
"7": "violet",
"8": "gray",
"9": "white"}