Jan-09-2021, 07:38 PM
(Jul-18-2018, 06:44 AM)buran Wrote:(Jul-18-2018, 12:11 AM)braankoo Wrote: Could it be done better?yes. it works, but is heavily influenced by your experience with other languages.
for example we don't use indexes to iterate over elements in a sequence. We reference the elements. And use enumerate if the index is needed too. So something more pythonic would be
def is_even(sequence): my_count = 0 for i, num in enumerate(sequence, start=1): my_count += sum(num>num2 for num2 in sequence[i:]) return not my_count % 2
This was interesting, understanding the enumerate was very helpful, can you please walkthrough was the += sum(num>num2 for num2 line is doing?