Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############### 301
- import re
- def letter_and_two_digits(s):
- if re.search(r'[A-Z]\d\d', s): # raw string
- return True
- return False
- ############### 302
- import re
- def extract_minutes(text):
- result = "<NONE>"
- pattern = "^(\d\d*):(\d\d*)"
- try:
- hour, minute = re.match(pattern, text).groups()
- if int(hour) < 24 and int(hour) >= 0:
- if int(minute) < 60 and int(minute) >= 0:
- result = minute
- finally:
- return result
- ######################33 303
- import re
- def build_divisable_pattern():
- pattern = "(00|"
- for i in range(1, 100):
- if i % 4 == 0:
- reg = str(i)
- if len(reg) == 1:
- reg = "0" + reg
- pattern += reg + "|"
- pattern = pattern[:-1] + ")$"
- return pattern
- def divisable_by_four(text):
- divisable_pattern = build_divisable_pattern()
- pattern = "(\d*" +divisable_pattern+ ")|^0$"
- result = re.match(pattern, text)
- if result and result.groups(0):
- return True
- return False
- #########################3 304
- import re
- def split_list(text):
- result = re.split("(\s*,\s*)|(:)", text)
- wynik = []
- for i in result:
- if i and re.match('\s*\w+\s*',i):
- wynik.append(i)
- return wynik
- ######################### 306
- """
- >>> 153131%25
- 6
- >>> 306 % 25
- 6
- """
- import re
- def is_power_of_hundred(text):
- if re.match("(^1)((00)*$)", text):
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement