Format all elements of a list

Posted by Curious2learn on Stack Overflow See other posts from Stack Overflow or by Curious2learn
Published on 2010-05-04T00:22:26Z Indexed on 2010/05/04 0:28 UTC
Read the original article Hit count: 648

Filed under:
|

I want to print a list of numbers, but I want to format each member of the list before it is printed. For example,

theList=[1.343465432, 7.423334343, 6.967997797, 4.5522577]

I want the following output printed given the above list as an input:

[1.34, 7.42, 6.97, 4.55]

For any one member of the list, I know I can format it by using,

print "%.2f" % member

Is there a command/function that can do this for the whole list. I can write one, but was wondering if one already exists.

Thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about list