Open alastair opened 5 years ago
I like to use pyflakes for checking my code while testing https://pypi.org/project/pyflakes/ Maybe it can be in the same tip with stylechecks (even if it is not properly a stylecheck)
student_tuples = [ ('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10), ] sorted(student_tuples, key=lambda student: student[2]) # sort by age [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
Sort with the lambda function. https://wiki.python.org/moin/HowTo/Sorting
sorting is a great item! especially using lambdas or the operator module for the key parameter.
More suggestions:
__slots__
(https://habr.com/en/post/458518/)example of splitting note sequence into phrases using itertools.groupby
:
>>> import itertools
>>> notes = ['sil', 'g', 'g', 'd', 'd', 'e', 'e', 'd', 'sil', 'c', 'c', 'b', 'b', 'a', 'a', 'g', 'sil']
>>> phrases = []
>>> for is_sil, group in itertools.groupby(notes, key=lambda note: note == 'sil'):
... if not is_sil:
... phrases.append(list(group))
...
>>> print(phrases)
[['g', 'g', 'd', 'd', 'e', 'e', 'd'], ['c', 'c', 'b', 'b', 'a', 'a', 'g']]
Some suggestions of tips to email people about how to do things better in python
+ '/' +