append ( my_list + 1 ) output_all_list_values ( my_list ) # Append a value use last value and add 10 to it: my_list. log ( "Current list value: " + v ) def main (): # Something new, a list with number values my_list = output_all_list_values ( my_list ) # Append a value use last value and add 1 to it: my_list.
#Squish code#
In the example above the code for outputting all list values is repeated three times, so it is useful to put that into a function and to then call the function instead:ĭef output_all_list_values ( the_list ): for v in the_list : test. Redundant code pieces should be put into functions. This tends to be error prone because it is easy to miss some of the code pieces.Īnother problem with redundancy is that it can make code harder to read and understand. The problem with code redundancy is that if the redundant code pieces should all be changed (for example to output the values along with their index in the list), then all code pieces have to be found and changed. log ( "Current list value: " + v ) test.py append ( my_list + 10 ) # Outputting the list values: for v in my_list : test. log ( "Current list value: " + v ) # Append a value use last value and add 10 to it: my_list. append ( my_list + 1 ) # Outputting the list values: for v in my_list : test. log ( "Current list value: " + v ) # Append a value use last value and add 1 to it: my_list. Def main (): # Something new, a list with number values my_list = # Outputting the list values: for v in my_list : test.