Skip to content

Instantly share code, notes, and snippets.

@NguyenDa18
Last active June 9, 2021 21:47
Show Gist options
  • Save NguyenDa18/6e570d0e8bf52e402816579a3dbe26d5 to your computer and use it in GitHub Desktop.
Save NguyenDa18/6e570d0e8bf52e402816579a3dbe26d5 to your computer and use it in GitHub Desktop.
Python Functions
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