1.
def random_pop(data):
number = random.randint(0, len(data)-1)
return data.pop(number)
2.
def random_pop(data):
number = random.choice(data)
data.remove(number)
return number
These two functions return the same value Why can't we express function number 2 as follows?
default_pop(data):
number = random.choice(data)
return data.pop(number)
The x value in pop(x) must be an index value.
>>> a = [1, 2, 3, 'a', 'b', 'c']
>>> a.pop(4)
'b'
>>> a
[1, 2, 3, 'a', 'c']
There is a big difference between the input value and the remove function that deletes the value as an element.
>>> a = [1, 2, 3, 'a', 'b', 'c']
>>> a.remove('a')
>>> a
[1, 2, 3, 'b', 'c']
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.