Voglio solo dividere ogni elemento in un elenco per un int.
myList = [10,20,30,40,50,60,70,80,90]
myInt = 10
newList = myList/myInt
Questo è l'errore:
TypeError: unsupported operand type(s) for /: 'list' and 'int'
Capisco perché ricevo questo errore. Ma sono frustrato di non riuscire a trovare una soluzione.
Ho anche provato:
newList = [ a/b for a, b in (myList,myInt)]
Errore:
ValueError: too many values to unpack
Risultato atteso:
newList = [1,2,3,4,5,6,7,8,9]
MODIFICARE:
Il seguente codice mi dà il risultato atteso:
newList = []
for x in myList:
newList.append(x/myInt)
Ma c'è un modo più semplice / veloce per farlo?