Il 18/03/2015 16:04, enrico franchi ha scritto:
tipo se fai un bel m.replace('x','') su una fantomatica stringa immutabile in Python, sei sempre O(N). E si... *forse* risparmi memoria. Che hai verosimilmente perso altrove per avere fatto copie difensive oppure hai appena introdotto un baco di azione a distanza (a meno che davvero nessuno a parte chi chiama replace abbia ownership dell'oggetto... che si, capita, eh... ).
Cacchio, non ho capito!

In [1]: s = "Hellox world"

In [2]: s1 = s

In [3]: s
Out[3]: 'Hellox world'

In [4]: s1
Out[4]: 'Hellox world'

In [5]: s = s.replace('x', '')

In [6]: s
Out[6]: 'Hello world'

In [7]: s1
Out[7]: 'Hellox world'

Il fatto che la stringa sia immutabile dovrebbe evitare quel tipo di bug?
Forse hai scritto "immutabile" ma intendevi "fantomatica stringa *mutabile*"? Scusa se posso sembrare puntiglioso, ma questi post per me sono preziose fonti di apprendimento.
Grazie
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a