Why when I try to remove the last item from the list by x.remove(x[-1]) it removes another item in another order in the list.
Why does it remove the element with index 2 and not the element with index -1 (which is the last element), when I tried this with another list it works, but here it doesn't work, and I don't understand why?!
I tried to convert all elements in the list into string(because some elements is an integar and other is a string), maybe it works, but it didn't
What I have tried:
x = []
for i in range(10):
y = int(input("Enter your grade: "))
x.append(y)
z = []
for n in range (len(x)):
for index in range(len(x)):
average = (x[n]+x[index])/2
if n == index:
continue
if average >= 0:
if not(x[n] in z) and not(x[index] in z):
z.append(x[n])
z.append (x[index])
z.append("---")
if z[-1] == "---":
z.remove(z[-1])
print (z)
for team in z:
print(team)
```
The result
[1, 2, 3, 4, '---', 5, 6, '---', 7, 8, '---', 9, 10, '---']
1
2
3
4
---
5
6
---
7
8
---
9
10
---
desired result
[1, 2, '---', 3, 4, '---', 5, 6, '---', 7, 8, '---', 9, 10]
1
2
---
3
4
---
5
6
---
7
8
---
9
10
<pre lang="Python"><pre lang="Python"><pre lang="Python">