如何使用“double for loop in python”获取不重复(复制)的数据(值)作为最后一个循环值

2024-04-27 01:01:28 发布

您现在位置:Python中文网/ 问答频道 /正文

是否将这些代码检查为python 产出(预期):['A':[10,11,12,13],'B':[1,2,3,4]] 但是,“B”值重复['A':[1,2,3,4],'B':[1,2,3,4]

import os
import glob
import pandas as pd
import numpy as np

Lotno_list = ['A','B']

count_merge = []
total_count = []
total_dict = {}

for Lotno in Lotno_list:
  folder_list = os.listdir(r'../{}/'.format(lotno)) # get the folder_list in the folder (Lotno) 
  count_merge.clear()
  for element in folder_list: # ex) folder_list = ['A01','A02','A03','A04'] when Lotno = 'A'into for
    element_list = os.listdir(r'../{}/{}/'.format(lotno,element)) 
    element_count = len(element_list)
    # Count files in the folder ex) A01 ... 
    count_merge.append(element_count) 
  total_dict[Lotno] = count_merge
print(total_dict)