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

前端 未结 2 383
别跟我提以往
别跟我提以往 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条回答
  •  醉梦人生
    2021-01-28 06:42

    If you are using Python3, len(data)/2 will return you a float if len(data) is odd. Use // instead of / to get an integer result.

提交回复
热议问题