Tory Rose
Tory Rose

Reputation: 41

Going from string to Base Ten in python

How do I convert ("1,0,1,1,0,0,1,0") to base ten. I keep finding answers for converting lists to base ten but not for when I already have this string

Upvotes: 4

Views: 61

Answers (2)

Veedrac
Veedrac

Reputation: 60127

Alternatively you can slice:

int(string[::2], 2)

Upvotes: 1

Kasravnd
Kasravnd

Reputation: 107287

You can use str.replace and int function :

>>> s="1,0,1,1,0,0,1,0"
>>> int(s.replace(',',''),2)
178

Upvotes: 4

Related Questions