Skip to content

Instantly share code, notes, and snippets.

@sarfarazahmad89
Last active March 15, 2019 08:22
Show Gist options
  • Save sarfarazahmad89/0e87731f9a4302adf819c1e56881ad2f to your computer and use it in GitHub Desktop.
Save sarfarazahmad89/0e87731f9a4302adf819c1e56881ad2f to your computer and use it in GitHub Desktop.
My Python Gists
** Filter, Lambda **
There are probably 10 other better ways to do this, but this is for my personal reference.
mylst = ['dummy-2019.01', 'dummy-testindex', 'dummy-2019.02']
def match_indices(index, regex):
return re.match(regex, index)
def match_indices_by_month_or_week(index):
return match_indices(index, '.*?\d{4}.\d{2}')
def match_indices_by_day(index):
return match_indices(index, '.*?\d{4}.\d{2}.\d{2}')
filter(match_indices_by_month_or_week, lst)
USING Lambda functions:
Becomes a one-liner
filter(lambda index: re.match('.*?\d{4}.\d{2}', index), lst)
If you use the root logger, nested/buried deep inside loggers can be a pain.
List of them like,
import requests
import logging
for key in logging.Logger.manager.loggerDict:
print(key)
Source : https://stackoverflow.com/questions/11029717/how-do-i-disable-log-messages-from-the-requests-library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment