diff --git a/tutorials/sqlite3_howto/code/print_db_info.py b/tutorials/sqlite3_howto/code/print_db_info.py index 285a635..ae2d671 100644 --- a/tutorials/sqlite3_howto/code/print_db_info.py +++ b/tutorials/sqlite3_howto/code/print_db_info.py @@ -65,9 +65,7 @@ def values_in_col(cursor, table_name, print_out=True): """ cursor.execute('PRAGMA TABLE_INFO({})'.format(table_name)) info = cursor.fetchall() - col_dict = dict() - for col in info: - col_dict[col[1]] = 0 + col_dict = {col[1]: 0 for col in info} for col in col_dict: c.execute('SELECT ({0}) FROM {1} ' 'WHERE {0} IS NOT NULL'.format(col, table_name)) diff --git a/useful_scripts/find_file.py b/useful_scripts/find_file.py index 8cbcc4d..6663d9f 100644 --- a/useful_scripts/find_file.py +++ b/useful_scripts/find_file.py @@ -6,11 +6,7 @@ import os def find_files(substring, path): - results = [] - for f in os.listdir(path): - if substring in f: - results.append(os.path.join(path, f)) - return results + return [os.path.join(path, f) for f in os.listdir(path) if substring in f] # E.g. # find_files('Untitled', '/Users/sebastian/Desktop/') diff --git a/useful_scripts/univariate_poisson_pdf.py b/useful_scripts/univariate_poisson_pdf.py index 30d3ae4..88afd6f 100644 --- a/useful_scripts/univariate_poisson_pdf.py +++ b/useful_scripts/univariate_poisson_pdf.py @@ -16,11 +16,7 @@ def likelihood_poisson(x, lam): Poisson distribution """ - if x // 1 != x: - likelihood = 0 - else: - likelihood = math.e**(-lam) * lam**(x) / math.factorial(x) - return likelihood + return 0 if x // 1 != x else math.e**(-lam) * lam**x / math.factorial(x) if __name__ == "__main__": diff --git a/useful_scripts/univariate_rayleigh_pdf.py b/useful_scripts/univariate_rayleigh_pdf.py index de0ae48..68f39e9 100644 --- a/useful_scripts/univariate_rayleigh_pdf.py +++ b/useful_scripts/univariate_rayleigh_pdf.py @@ -6,8 +6,7 @@ def comp_theta_mle(d): dataset for a Rayleigh distribution. """ - theta = len(d) / sum([x**2 for x in d]) - return theta + return len(d) / sum(x**2 for x in d) def likelihood_ray(x, theta): """