3
Contributors
6
Replies
17
Views
2 Years
Discussion Span
Last Post by vegaseat
Featured Replies
  • 2

    Something like this ... mylist = [2,4,4] number = int("".join(str(n) for n in mylist)) print(number, type(number)) Read More

2

Something like this ...

mylist = [2,4,4]
number = int("".join(str(n) for n in mylist))
print(number, type(number))
0

This is very similar to your previous question. Take the time to understand how the code works

number = int(''.join(mylist))

Edited by Gribouillis

0

Thank you @vegaseat.
Could you make more clrear this line for me please?

number = int("".join(str(n) for n in mylist))

int means return ( ) into integer.
"".join means add no-space to the ( ).
I can't understand this completely str(n) for n in mylist, what does it exactly do?

-------------------------------------
@Gribouillis, with this:

mylist = [6, '/', 3, '+', 9, '+', 8, '+', 1, '/', 2]
number = int(''.join(mylist))
print number

I got this error:

    number = int(''.join(mylist))
TypeError: sequence item 0: expected string, int found
0

with this:

mylist = [2,4,4]
number = int(''.join(mylist))
print number

I got this error:

    number = int(''.join(mylist))
TypeError: sequence item 0: expected string, int found
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.