Occasionally we may encounter Python expressions inside string literals, such as reading in code from a file or API. In these cases we can transform these strings into the underlying expressions using the
literal_eval is a safer alternative to the
eval function, and is preferable if the data source (i.e.
string_with_list in our example) is not trusted. You can read more about the differences between
eval in this Stack Overflow question.