If you want to start with the third element of the given list and retrieve a new list containing only those elements, you can modify the code as follows:
data = ['tikka', '', 'Calories: 200', 'Fat: 11g', 'Carbohydrates: 8g', 'Protein: 15g', 'Sodium: 250mg', 'Fiber: 0g', 'Sugar: 6g']
# Start with the third element of the list
data = data[2:]
# Create a new list to store the desired elements
desired_list = []
# Iterate over the data
for item in data:
# Check if the item starts with a colon (':')
if item.startswith(':'):
# Remove the colon and any leading/trailing whitespaces from the item
item = item[1:].strip()
# Append the modified item to the desired list
desired_list.append(item)
# Print the desired list
print(desired_list)
Output:
['Calories: 200', 'Fat: 11g', 'Carbohydrates: 8g', 'Protein: 15g', 'Sodium: 250mg', 'Fiber: 0g', 'Sugar: 6g']
Top comments (0)