Tim Chase wrote: > While working on a Jumble-esque program, I was trying to get a string > into a character array. Unfortunately, it seems to choke on the following > > import random > s = "abcefg" > random.shuffle(s) > > returning > > File "/usr/lib/python2.3/random.py", line 250, in shuffle > x[i], x[j] = x[j], x[i] > TypeError: object doesn't support item assignment
Yes, Python has had that same problem elsewhere, notably the mutating methods 'sort' and 'reverse'. Those problems are now reasonably well solved. What's really neat is that the names of the new methods: 'sorted' and 'reversed', are adjectives describing the return values we want, where 'sort' and 'reverse' are verbs, calling for procedures to be performed. For sorting, we had the procedure 'sort', then added the pure function 'sorted'. We had a 'reverse' procedure, and wisely added the 'reversed' function. Hmmm... what we could we possible do about 'shuffle'? -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list