Last active
June 9, 2021 21:47
-
-
Save NguyenDa18/6e570d0e8bf52e402816579a3dbe26d5 to your computer and use it in GitHub Desktop.
Python Functions
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 | |
def batch_data(Items, size): | |
result = [] | |
i = 0 | |
while (i < len(Items)): | |
batch = Items[i:i + size] | |
result.append(batch) | |
i = i + size | |
return result | |
def remove_parens(string: str): | |
nums_in_parens = re.compile(r"\((\d+)\)") | |
return re.sub(nums_in_parens, '', string) | |
def remove_spaces(string: str): | |
pattern = re.compile(r'\s+') | |
return re.sub(pattern, '', string) | |
def list_item_in_str(list, string: str): | |
str_in_list = [word in string for word in list] | |
return any(str_in_list) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment