I'm new to Python and trying to learn to use a for statement to display information in a certain way.... Is there a way to use the for statement to display a list like this?
w = "Fa1/1 connected 42 a-full a-100 10/100BaseTX"
v = w.split()
x=v[0]
print "Port ", x
y=v[1]
print "Status ", y
z=v[2]
print "VLAN ", z
a=v[3]
print "Duplex ", a
b=v[4]
print "Speed ", b
c=v[5]
print "Type ", c
-------------------------
Port Fa1/1
Status connected
VLAN 42
Duplex a-full
Speed a-100
Type 10/100BaseTX
I have tried a lot of different methods but keep getting value and index errors....
Thanks for any help....
Something like this?
>>> w = "Fa1/1 connected 42 a-full a-100 10/100BaseTX"
>>> firstList = ['Port', 'Status', 'VLAN', 'Duplex', 'Speed', 'Type']
>>> testList = zip(firstList, w.split())
>>> for a, b in testList:
print a, b
Port Fa1/1
Status connected
VLAN 42
Duplex a-full
Speed a-100
Type 10/100BaseTX
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With