-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_index.py
27 lines (20 loc) · 953 Bytes
/
list_index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Travel Packing List and Selection
packing_list = ['clothes', 'toothbrush', 'passport', 'camera']
item_to_check = 'passport'
# Check if the item is in the packing_list
is_item_packed = item_to_check in packing_list
# Find the index of item_to_check
item_index = packing_list.index(item_to_check) if is_item_packed else -1
# Print out the results
print("Is the item packed?", is_item_packed)
print("Item index:", item_index)
# Travel Packing List and Selection
packing_list = ['clothes', 'toothbrush', 'passport', 'camera']
item_to_check = 'passport'
# Check if the item_to_check is in the packing_list
is_item_packed = item_to_check in packing_list # This line defines is_item_packed
# Find the index of item_to_check in the list if it is packed, otherwise set it to -1
item_index = packing_list.index(item_to_check) if is_item_packed else -1
# Print out the results
print("Is the item packed?", is_item_packed)
print("Item index:", item_index)