为什么只打印第一项

时间:2019-11-23 17:28:58

标签: python

想知道为什么在for循环后写return arg时,我得到了整个列表,但是当返回return时,只打印了我提供的列表中的最后一个值

def reverse_complement(**seqs):
   for arg in seqs.values():
      reverse=arg[::-1]
   return reverse

print(reverse_complement(a='CGTC', b='ATATAT', c='TATA', d='GCGTCGC'))

给予:

CGCTGCG

2 个答案:

答案 0 :(得分:0)

将结果存储在list中,然后重新存储list

使用此:

def reverse_complement(**seqs):
   results=[]
   for arg in seqs.values():
      reverse=arg[::-1]
      results.append(reverse)
   return results

print(reverse_complement(a='CGTC', b='ATATAT', c='TATA', d='GCGTCGC'))

['CTGC', 'ATAT', 'TATATA', 'CGCTGCG']

答案 1 :(得分:-1)

要返回整个序列(带有键),请返回一个字典:

ViewBox

这给出了:

<Canvas>
    <Canvas.Background>
        <VisualBrush TileMode="Tile" Viewport="0,0,20,20" ViewportUnits="Absolute" Viewbox="0,0,20,20" ViewboxUnits="Absolute">
            <VisualBrush.Visual>
                <Grid Width="20" Height="20">
                    <Ellipse Height="2" Width="2" Stroke="Black" StrokeThickness="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-1,-1" />
                    <Ellipse Height="2" Width="2" Stroke="Black" StrokeThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="-1,-1"/>
                    <Ellipse Height="2" Width="2" Stroke="Black" StrokeThickness="1" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="-1,-1"/>
                    <Ellipse Height="2" Width="2" Stroke="Black" StrokeThickness="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="-1,-1"/>
                </Grid>
            </VisualBrush.Visual>
        </VisualBrush>
    </Canvas.Background>
    <Canvas.Children>
        <Rectangle Canvas.Left="40" Canvas.Top="40" Width="100" Height="80" Fill="Yellow" Stroke="blue" />
    </Canvas.Children>
</Canvas>

作为输出。