python pulls all integers and floats from a string

Keep it simple

spam = '[47.2, 46.6, 46.4, 46, 45.7, 45.54, 45.29, 45.01, 44.79, 44.54, 44.15, 0]'

#using json
import json
eggs = json.loads(spam)
print(eggs)

# ast.literal_eval
from ast import literal_eval
eggs = literal_eval(spam)
print(eggs)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top