Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
The first square brackets contain a list of values to be returned. The second square brackets contain an expression whose calculation results in a slice for the first list. bin_str. count ("1")%2 means that we calculate the number of occurrences of' 1 ' in bin_str and check whether the number of units is even. (parity = = "even") will give 1 or 0 depending on whether an even number of units is expected or an odd one. in essence, it looks something like this:
imagine that bin_str is equal to '010101' and parity is equal to 'even'
[0, 1][bin_str.count("1") % 2 == (parity == "even")] = [0, 1][3 % 2 == (parity == "even")] = [0, 1][3 % 2 == (1)] = [0, 1][1 == (1)] = [0, 1][1] = 1
Here it is necessary to understand that when comparing (==) two operands, it turns out True if they are equal and False if they are not equal. True is the same as 1 False is the same as 0. True = 1, False = 0. True+True = 2, False + False = 0, ... I hope it helped somehow, if something is wrong experienced wars will correct.