PY
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
28
# Creator: Per Bratthammar (2021-07-19) v1.1
"""
Demo: Using list.pop(i).
"""
# Constants.
LIST_LEN = 8
SHORT_LOOP_LEN = 3
MSG = {
'sep': f"{20 * '- '}",
'pop_pos_index': "'pop' in index order can give unexpected results:",
'pop_neg_index': "'pop' elements in order from original list using negative index:"
}
# Create lists.
original_list = list(range(LIST_LEN))
negative_index_list = original_list.copy()
# list.pop(i), where i >= 0
print(
f"{MSG['sep']}\n"
f"{MSG['pop_pos_index']}\n"
f"{MSG['sep']}\n\n"
f"{original_list = }\n"
)
for i in range(SHORT_LOOP_LEN):
print(
f"{i = }\n"
f"original_list.pop({i}) "
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run