Xylight (Photon dev) to Programmer [email protected] • 1 year agoI don't want to use ternarieslemmy.xylight.devimagemessage-square18fedilinkarrow-up1148arrow-down111
arrow-up1137arrow-down1imageI don't want to use ternarieslemmy.xylight.devXylight (Photon dev) to Programmer [email protected] • 1 year agomessage-square18fedilink
minus-square@aidanlink4•1 year agoReminds me when my I did all my homework using list comprehension, ternary operations, and lambda expressions because it was boring. Here’s an example def task03( matrix ): print((new_matrix := [[ (y if y != 0 else ( temp := sum([r[j] for r in matrix[0:i]] + x[j:]), zeros_sum := (zeros_sum if 'zeros_sum' in locals() else 0) + temp)[0] ) for j,y in enumerate(x)] for i,x in enumerate(matrix)], '\n'.join( [ ' '.join([str(new_matrix[o][p]) for p in range(0 if len(matrix[0]) <= 20 else len(matrix[0])-20, len(matrix[0]))]) for o in range(0 if len(matrix) <= 20 else len(matrix)-20, len(matrix)) ] ) + '\n' + str(zeros_sum) )[1] )
Reminds me when my I did all my homework using list comprehension, ternary operations, and lambda expressions because it was boring. Here’s an example
def task03( matrix ): print((new_matrix := [[ (y if y != 0 else ( temp := sum([r[j] for r in matrix[0:i]] + x[j:]), zeros_sum := (zeros_sum if 'zeros_sum' in locals() else 0) + temp)[0] ) for j,y in enumerate(x)] for i,x in enumerate(matrix)], '\n'.join( [ ' '.join([str(new_matrix[o][p]) for p in range(0 if len(matrix[0]) <= 20 else len(matrix[0])-20, len(matrix[0]))]) for o in range(0 if len(matrix) <= 20 else len(matrix)-20, len(matrix)) ] ) + '\n' + str(zeros_sum) )[1] )
you monster