Python: For statement to display a list with specific strings? -
i'm new python , trying learn use statement display information in way.... there way use statement display list 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 ", 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 lot of different methods keep getting value , index errors....
thanks help....
something this?
>>> w = "fa1/1 connected 42 a-full a-100 10/100basetx" >>> firstlist = ['port', 'status', 'vlan', 'duplex', 'speed', 'type'] >>> testlist = zip(firstlist, w.split()) >>> a, b in testlist: print a, b port fa1/1 status connected vlan 42 duplex a-full speed a-100 type 10/100basetx
Comments
Post a Comment