Relative Content

Tag Archive for pythonlistindexing

How to get multiple indices in a list [duplicate]

This question already has answers here: How to find all occurrences of an element in a list (20 answers) Closed last month. How can i get 2 or more indices of a certain value from a list? e.g. list = [5, 1, 5] list_max = max(list) list_max_indices = list.index(list_max) In this way list_max_indices returns me […]

list indexing in print function

todos = []
print(“Welcome to todo app”)
while True:
print(“What do you want to do? “)
user_action = input(“‘add’, ‘show’, ‘edit’ , ‘delete’ or ‘exit’: “).lower().strip()
match user_action:
case ‘add’:
todo = input(“Enter a todo: “)
todos.append(todo)
case ‘show’:
i = 1
for item in todos:
print(f”{i}. {item}”)
i += 1
case ‘edit’:
edit_todo_index = int(input(“Enter number of todo which you want to edit: “))
# todos[editing_todo_index] = input(“Enter new todo: “)
todos.setitem(edit_todo_index – 1, input(“Enter a new todo: “))
case ‘delete’:
todo_index = int(input(“which todo you want to delete: “))
deleting_todo = todos[todo_index – 1]
todos.remove(deleting_todo)
print(f”todo ‘{todos[todo_index – 1]}’ wad deleted successfully”)
case ‘exit’:
break
if len(todos) > 0:
print(f”n$$$ Todo app was created Successfully $$$n”)
else:
print(f”n$$$ todo app is empyt $$$n”)