遍历字典键和项时发生TypeError

时间:2018-12-28 09:26:28

标签: python-3.x dictionary for-loop typeerror

我有一本字典,当我尝试遍历其键和值时,它抛出了一个错误:

  

TypeError:items()不接受任何参数(给定1个)

BDT_param_grid1 ={"learning_rate": np.arange(0.1,1.0,0.1),
                  "n_estimators": np.arange(1, 1000, 10),
                  "base_estimator__min_samples_split": np.arange(0.1,1.0,0.1),
                  "base_estimator__min_samples_leaf": np.arange(1,60,1),
                  "base_estimator__max_leaf_nodes": np.arange(2,60,1),
                  "base_estimator__min_weight_fraction_leaf": np.arange(0.1, 0.4, 0.1),
                  "base_estimator__max_features": np.arange(0.1,1,0.1),
                  "base_estimator__max_depth": np.arange(1, 28, 1)}

for key,items in dict.items(BDT_param_grid1):
    print(key,items)

我的预期结果是:

learning_rate [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
n_estimators [  1  11  21  31  41  51  61  71  81  91 101 111 121 131 141 151 161 171
 181 191 201 211 221 231 241 251 261 271 281 291 301 311 321 331 341 351
 361 371 381 391 401 411 421 431 441 451 461 471 481 491 501 511 521 531
 541 551 561 571 581 591 601 611 621 631 641 651 661 671 681 691 701 711
 721 731 741 751 761 771 781 791 801 811 821 831 841 851 861 871 881 891
 901 911 921 931 941 951 961 971 981 991]
base_estimator__min_samples_split [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
base_estimator__min_samples_leaf [ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
 49 50 51 52 53 54 55 56 57 58 59]
base_estimator__max_leaf_nodes [ 2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 50 51 52 53 54 55 56 57 58 59]
base_estimator__min_weight_fraction_leaf [0.1 0.2 0.3 0.4]
base_estimator__max_features [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
base_estimator__max_depth [ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 25 26 27]

安静,因为我能够在同一代码中更早地获得结果而没有任何错误

0 个答案:

没有答案