This question already has answers here:
Why does map return a map object instead of a list in Python 3?
(4 answers)
Getting a map() to return a list in Python 3.x
(11 answers)
Closed 5 years ago.
How to Convert a string like '123' to int 1,2 and 3 so that I can perform 1+2+3. I am new to python. Can you please help me? I am not able to split the list. I don't think splitting the string will be of any use as there are no delimiters. Can you help me to understand how can this string elements be separated and treated as intergers?
x = "123"
s = 0
for a in x:
s = int(a) + s
Related
This question already has answers here:
How do I convert a list into a string with spaces in Python?
(6 answers)
Closed 1 year ago.
I have following elements within a list b['lemma'] within a function:
babicka
Marta
I want to return them as string like:
print(b['lemma'], end=" ")
>> babicka Marta
Help would be appreciated.
Use the string join() method, like this:
return " ".join(b['lemma'])
This question already has answers here:
could not convert string to float (python)
(2 answers)
Closed 2 years ago.
I want to convert
[('23.758481',), ('23.761419',), ('23.762254',)]
into
[ 23.75848,23.761419,23.762255]
in python
If:
l = [('23.758481',), ('23.761419',), ('23.762254',)]
you could do:
[float(i[0]) for i in l]
this gives:
[23.758481, 23.761419, 23.762254]
what we do here is that, we take the first elements out of the tuples.
Or we could use extend():
res = []
[res.extend(i) for i in l]
This question already has answers here:
How to extract numbers from a string in Python?
(19 answers)
extract digits in a simple way from a python string [duplicate]
(5 answers)
Closed 3 years ago.
I have the following string:
string_a = 81^A55
from which I'm trying to get the following list
string_a_int = [81,55]
I'm able to split the string into a list made by numbers as follows
list_only_number = re.split('[A-Z]+', string_a)
list_only_numbers = [81^, 55]
but I'm trying to figure out how to skip also the ^.
Any help would be much appreciated.
This question already has answers here:
Print a string as hexadecimal bytes
(13 answers)
Closed 7 years ago.
I want to convert string to a hex (decimal),
for example abc to 616263 and so on.
How do I do that?
I have tried:
x= input("Enter string")
x = int(x)
hex(x)
But it is not working.
maybe you are looking for something like:
x.encode("hex")
This question already has answers here:
Converting a list to a string [duplicate]
(8 answers)
Closed 9 years ago.
I have a python list like so:
list = []
for loop
list.append("blah")
What I want to do it convert this list to string with each value separated by comma.
How do I do this??
Use the str.join method:
','.join(your_list)