"spir" wrote
Is there a list.replace builtin I cannot find? Or a workaround?
myList[x] = newValue
Or is that too obvious?
Also: How would perform string.swap(s1, s2) in the following cases:
* There is no secure 'temp' char, meaning that
s.replace(s1,temp).replace(s2,s1).replace(temp,s2)
On Tue, Mar 17, 2009 at 7:01 AM, spir wrote:
> Is there a list.replace builtin I cannot find? Or a workaround?
Just assign directly to list elements. To replace s1 with s2 in l:
for i, x in enumerate(l):
if x == s1:
l[i] = s2
> Also: How would perform string.swap(s1, s2) in the following
Hello Denis,
spir wrote:
Is there a list.replace builtin I cannot find? Or a workaround?
You didn't find it because it does not exist.
You should do something like
[f(x) for x in old_lst]
where f(x) implements the replacement.
Also: How would perform string.swap(s1, s2) in the following c
Is there a list.replace builtin I cannot find? Or a workaround?
Also: How would perform string.swap(s1, s2) in the following cases:
* There is no secure 'temp' char, meaning that
s.replace(s1,temp).replace(s2,s1).replace(temp,s2)
will fail because any char can be part of s.
* Either s