Combining digit in a list to make an integer

Dan Bishop danb_83 at yahoo.com
Fri Apr 1 07:00:35 EST 2005


Harlin Seritt wrote:
> If anyone has time, would you mind explaining the code that Dan
Bishop
> was so kind as to point out to me:
>
> int(''.join(num1))
>
> This worked perfectly for me, however, I'm not sure that I understand
> it very well.

join(...)
    S.join(sequence) -> string

    Return a string which is the concatenation of the strings in the
    sequence.  The separator between elements is S.

For example:

>>> '<'.join(['1', '2', '3'])
'1<2<3'

If you don't want a separator, simply let S be the empty string ('').




More information about the Python-list mailing list