我有以下函数,它使用cycle_times的字典来生成包含值大于某个阈值的元素的列表和字典。
def anamolous_cycle_time_index_and_lengths(cycle_time_dict, anamoly_threshold):
for meter,cycle_time_list in cycle_time_dict.items():
anamoly_dict = {cycle_time_list.index(x):x for x in cycle_time_list if x > anamoly_threshold}
anamoly_list = [x for x in cycle_time_list if x > anamoly_threshold]
print(meter,len(anamoly_dict))
print([value for key,value in anamoly_dict.items()])
print(anamoly_list)
假设我将输入设为
new_dict = {104:[2,3,4,5,6,7,3,2,5,6,7], 101:[2,45,4,2,5,2,34,2,5,6,7], 106:[2,23,4,5,65,7,3,23,5,6,7]}
anamoly_threshold = 3
我得到的输出是
104 4
[4, 5, 6, 7]
[4, 5, 6, 7, 5, 6, 7]
101 6
[45, 4, 5, 34, 6, 7]
[45, 4, 5, 34, 5, 6, 7]
106 6
[23, 4, 5, 65, 7, 6]
[23, 4, 5, 65, 7, 23, 5, 6, 7]
列表和字典不应该给我相同的输出吗?我已经对同一数据的两个数据结构进行了理解。