TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

'in-place' string modifications in Python

1 点作者 sea6ear超过 1 年前

1 comment

necovek超过 1 年前
As pointed out, strings are immutable and depending on F(c) being mostly c or not, different approaches might work best.<p>Eg. for a single replacement (I haven&#x27;t seen this one mentioned), slicing might work best: s[:i-1] + F(s[i]) + s[i+1:]. This is obviously good for a small number of replacements too, though you might want to switch to &quot;&quot;.join(iterable) for better performance.<p>In general, immutability of strings requires a more functional approach than in-place editing.