# Initialize the list my_list = ['apple', 'banana', 'cherry']
# Convert the list into a dictionary my_dict = {i: my_list[i] for i in range(len(my_list))}
# Print the dictionary print(my_dict)
In this example, a list called my_list is initialized with three strings: 'apple', 'banana', and 'cherry'. This list is then converted into a dictionary called my_dict using a dictionary comprehension. The keys of the dictionary are the indices of the items in the list, and the values are the items themselves.
Note: This example uses a simple dictionary comprehension to convert the list into a dictionary. Other approaches, such as using the dict() function, can also be used to achieve the same result.
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.