I mostly do C/C++ development, but the task of writing an application in Python-3 came up and I ran into some misunderstanding of the interpreter.
I made a mistake and didn't notice it for a while because Python did everything "almost" right. The task was to remove N/2 values from the list, where N is their total number.
A simple example describing the situation:
array=  for i in range(10): array append(i) # array [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] i= 0 for item in array: if i < len(array)/2: array.remove(item) #array [1, 3, 5, 7, 9]
As you can see, I don't increment the variable
iin the second loop, but the interpreter somehow still removes zero and every even element from the array.
Actually, how does it work?
- python : Pass one list to another list, then update the second list when the first one changes?
- Compare custom list and list of lists (comparing lists of different lengths) Python
- python : List index out of range error, don't know how to fix it [duplicate]
- TypeError: 'list' object is not callable. Literally today I started learning Python and telebot API and I don’t understand what
- python : How to add an element from list 1 to a dictionary in list 2?
- python : Sending a file using telegramAPI
- Program for finding synonyms of Russian words python
- python : How to create a window in the game for example (dota2)