Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions tutorials/sqlite3_howto/code/print_db_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function values_in_col refactored with the following changes:

  • Replace dict() with {}
  • Convert for loop into dictionary comprehension

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))
Expand Down
6 changes: 1 addition & 5 deletions useful_scripts/find_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import os

def find_files(substring, path):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function find_files refactored with the following changes:

  • Convert for loop into list comprehension
  • Inline variable that is only used once

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/')
Expand Down
6 changes: 1 addition & 5 deletions useful_scripts/univariate_poisson_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ def likelihood_poisson(x, lam):
Poisson distribution

"""
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function likelihood_poisson refactored with the following changes:

  • Replace if statement with if expression
  • Inline variable that is only used once

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__":
Expand Down
3 changes: 1 addition & 2 deletions useful_scripts/univariate_rayleigh_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ def comp_theta_mle(d):
dataset for a Rayleigh distribution.

"""
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function comp_theta_mle refactored with the following changes:

  • Inline variable that is only used once
  • Replace unneeded comprehension with generator

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):
"""
Expand Down