error :list indices must be integers, not float for median

前端 未结 2 396
别跟我提以往
别跟我提以往 2021-01-28 06:04

Trying to find median but keep getting list indices must be integers, not float error and am not sure what to do.

sorted_data = sorted(data, key=lambda d:d.a         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 06:45

    The statistics module is part of the standard library:

    import statistics
    
    data = [1, 2, 3, 4]
    statistics.median(data)
    

提交回复
热议问题