Mar-09-2018, 10:46 AM
I've defined the third element in each list item as a float, but I want to convert them to currency format:
#!/usr/bin/env python3 #SamsLists.py movies = [["Monty Python and the Holy Grail", 1975, 9.99], ["Uncle Bazerko's Violent Adventure", 2011, 9.99], ["The Expendables", 2010, 9.99], ["Duke Nukem: Fate of Humanity", 2019, 11.99]] i = 0 for i in movies: movies[i][("${:,.2f}".format(movies[2]))] i += 1 for movie in movies: print(movie) print() print(movies)The error was:
Error:========= RESTART: I:/Python/Python36-32/SamsPrograms/MovieList2D.py =========
Traceback (most recent call last):
File "I:/Python/Python36-32/SamsPrograms/MovieList2D.py", line 11, in <module>
movies[i][("${:,.2f}".format(movies[2]))]
TypeError: list indices must be integers or slices, not list
>>>
My desired output is:Output:['Monty Python and the Holy Grail', 1975, $9.99]
["Uncle Bazerko's Violent Adventure", 2011, $9.99]
['The Expendables', 2010, $9.99]
['Duke Nukem: Fate of Humanity', 2019, $11.99]
What do I need to do?