print function in Python
I need some help in Python, to print:
I have:
input =[(3, 'x1'), (5, 'x3'), (2, 'x2')]
开发者_如何学JAVA
need to print, in this form:
x1=3 x2=2 x3=3
Many thanks
print ' '.join('%s=%s' % (k, v) for (v, k) in input)
for x,y in input:
print "%s=%s" % (y, x),
input =[(3, 'x1'), (5, 'x3'), (2, 'x2')]
for i,j in input:
print("{}={}".format(j,i),end=" ")
print j,i because second one will come before first. Format is function used to print the values. If u want to print above in different lines rather than single then remove end=" "
精彩评论