Saturday, August 18, 2012

Using lambda functions for sorting in Python

Give a list L = [56, 78, 98, 34] the following one linear will sort the elements in the descending order of their values.
L.sort(lambda x, y: 1 if y > x else -1)

No comments:

Post a Comment

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1