我有一个for循环语句,我想按顺序打印列表或数组中的所有信息。
所需的输出:
revised_grand_average
不幸的是,这是我收到的输出:
<div class="wrapper">
<div class="item-block">
<div class="props">
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">dolor sit amet,</div>
<div class="prop-item"> consectetur adipisicing elit. Voluptatum f</div>
<div class="prop-item">ugit magnam at, beatae ducimus, maiores, voluptas minus cumque quos est officiis a. Alias distinctio optio odio maxime nihil, deleniti in.</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">Lorem ipsum</div>
</div>
</div>
<div class="item-block">
<div class="props">
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">dolor sit amet,</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item"> consectetur adipisicing elit. Voluptatum f</div>
<div class="prop-item">ugit magnam at, beatae ducimus, maiores, voluptas minus cumque quos est officiis a. Alias distinctio optio odio maxime nihil, deleni</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">Lorem ipsum</div>
</div>
</div>
<div class="item-block">
<div class="props">
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">dolor sit amet,</div>
<div class="prop-item"> consectetur adipisicing elit. Voluptatum f</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">ugit magnam at, beatae ducimus, maiores, voluptas minus cumque quos est officiis a. Alias distinctio optio odio maxime nihil, delenit</div>
</div>
</div>
<div class="item-block">
<div class="props">
<div class="prop-item">ugit magnam at, beatae ducimus, maiores, voluptas minus cumque quos est officiis a..</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">dolor sit amet,</div>
<div class="prop-item"> consectetur adipisicing elit. Voluptatum f</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">Lorem ipsum</div>
<div class="prop-item">Lorem ipsum</div>
</div>
</div>
</div>
它似乎遍历第三个数组。我认为嵌套循环设置不正确。
BUS: 1 JBUS: 12 ICKT: 1
IBUS: 3 JBUS: 12 ICKT: 1
IBUS: 4 JBUS: 16 ICKT: 1
IBUS: 5 JBUS: 12 ICKT: 1
IBUS: 1 JBUS: 14 ICKT: 2
IBUS: 2 JBUS: 11 ICKT: 1
答案 0 :(得分:2)
我认为该错误是由于嵌套循环引起的。这应该起作用:
FROM_BUS=[1,3,4,5,1,2]
TO_BUS=[12,12,16,12,14,11]
CKT=[1,1,1,1,2,1]
for f,t,c in zip(FROM_BUS, TO_BUS, CKT):
print('IBUS: ' + str(f) + ' JBUS: ' + str(t) + ' ICKT: ' + str(c))
答案 1 :(得分:0)
使用numpy的另一种方法
import numpy as np
FROM_BUS=[1,3,4,5,1,2]
TO_BUS=[12,12,16,12,14,11]
CKT=[1,1,1,1,2,1]
a=np.array([FROM_BUS,TO_BUS,CKT])
a=a.transpose()
for i in a:
print('IBUS: {} JBUS: {} ICKT: {}'.format(*i))
输出:
IBUS: 1 JBUS: 12 ICKT: 1
IBUS: 3 JBUS: 12 ICKT: 1
IBUS: 4 JBUS: 16 ICKT: 1
IBUS: 5 JBUS: 12 ICKT: 1
IBUS: 1 JBUS: 14 ICKT: 2
IBUS: 2 JBUS: 11 ICKT: 1