The list attendance records the name of each student who came to the Python club, one item per visit. Create selam_visits: how many times “Selam” appears. Use count(). Create first_hana: the index of the first “Hana”. Use index(). Print both. …
A bus visits some towns in the morning and some in the evening. Some towns appear in both lists. Build all_stops: Start with a real copy of morning. Loop through evening and append() each town only if it is not …
Two small teams are joining for a football match in Keren. Create school_team, a new list with all the players of team_a followed by all the players of team_b. Use the + operator, so the two original lists do not …
Make three real copies of cities, each in a different way: copy1 with copy() copy2 with list() copy3 with a full slice [:] Then change each copy: add “Assab” to the end of copy1, replace the first item of copy2 …
Abel wants to keep a backup of his task list before adding a new task. But the program below has a bug: the backup changes too! Fix the line that creates backup so it makes a real copy with copy(). …
Using the list towns, create three new lists or values. The list towns itself must stay unchanged, so use sorted(). by_length — the towns sorted from shortest to longest name (key=len). longest — the last item of by_length. reverse_alpha — …
Two lists are given. Create alphabetical: a new list with the names sorted A to Z, ignoring capital letters. Use sorted() with key=str.lower. The list names must not change. Sort the list marks itself from highest to lowest with sort(). …
These are the highest temperatures (°C) in Massawa for six days. Use list comprehensions to create: hot_days — only the temperatures above 30. labels — for every day, “hot” if the temperature is above 30, else “ok”. doubled — every …
Use list comprehensions to create two new lists from names: upper_names — every name in capital letters (use .upper()). long_names — only the names with more than 4 letters (use len() in a condition). Print both lists. Expected output: [‘SELAM’, …
A café in Asmara has two lists in the same order: items and prices. Use for i in range(len(items)): to print a numbered menu, and add each price to total. Then print the total. The numbers on the menu start …
