How to format a string from an array?

rocksportrocker rocksportrocker at googlemail.com
Wed Jun 13 07:02:41 EDT 2007


On Jun 13, 11:11 am, Allen <pruyu.c... at gmail.com> wrote:
> a = range(256)
> I want to output the formated string to be:
> 00 01 02 03 04 05 06 07   08 09 0a 0b 0c 0d 0e 0f
> 10 11 12 13 14 15 16 17   18 19 1a 1b 1c 1d 1e 1f
> ........................................................................
> f0 f1 f2 f3 f4 f5 6 f7   f8 f9 fa fb fc fd fe ff
>
> How to do it?

You can start with

   hex_list = [  ("0"+hex(i)[2:])[-2:] for i in a ]

This statement generates a list [ "00", "01", ... "ff"].

Now you only have to print this list.

Greetings, Uwe




More information about the Python-list mailing list