获取字典中列表的平均值

时间:2020-08-31 01:17:59

标签: python

我有一本字典,里面有列表,例如:

dict = {'Monday,': [10, 20], 'Tuesday,': [20, 20], 'Wednesday,': [30, 40], 'Thursday,': [5, 25], 'Friday,': [100, 20], 'Saturday,': [40, 10], 'Sunday,': [35, 25]}

我需要获取每天的平均值,例如:

{'Monday,': [15.00], 'Tuesday,': [20.00], 'Wednesday,': [35.00], 'Thursday,': [15.00], 'Friday,': [60.00], 'Saturday,': [25.00], 'Sunday,': [30.00]}

我现在有这个,但它不起作用

average = sum(dict) / len(dict)

1 个答案:

答案 0 :(得分:4)

首先,请不要将 describe('Input Error Check', () => { const fixture = TestBed.createComponent(AppComponent); afterEach( () => { const searchButon = fixture.debugElement.query(By.css('#searchButton')).nativeElement as HTMLButtonElement expect(searchButon.disabled).toBeTruthy() }) it('No Input Value', () =>{ // write test code }) it('Invalid Input Value', () =>{ // write test code }) }) 命名为dict,因为这是内置的python的名称

这将为您服务:

dict

但是请注意,您假定所有列表都是数字,并且没有列表为空。