将 python 列表和字符串合并
问题:
我有一个 reference 字符串和一个 referid 列表,我想将它们连接起来,使得 reference 字符串的后面带有 referid 的内容。
示例代码:
立即学习“Python免费学习笔记(深入)”;
reference = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=" reg = r'.+/(\d+)_p0' referid = re.findall(reg, item) # id=后面的 id
答案:
要将 reference 字符串和 referid 列表合并,可以通过循环的方式来实现:
# 循环遍历 referID 列表,依次拼接 output = [] for id in referID: output.append(f"{reference}{id}") # 将拼接后的列表转换为字符串输出 result = ", ".join(output)
这样,result 变量就包含了合并后的字符串。你可以根据需要使用它。
以上就是如何将 Python 列表和字符串合并,并在字符串后添加列表元素?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号