gpt4 book ai didi

python - 从行中搜索数字并放在特定句子中

转载 作者:太空宇宙 更新时间:2023-11-04 09:45:29 24 4
gpt4 key购买 nike

我正在努力处理一些 python 代码。

我有一个包含很多行的文件,例如

50
22
35
41

我希望将这些添加到结构相似的句子中,但保持行的顺序。

例如

This is test 50 of this friday
This is test 22 of this friday
This is test 35 of this friday
This is test 41 of this friday

最佳答案

您使用 pythonawk 标记了问题。对于这种微不足道的 awk 似乎是明确的选择:

$ awk '{printf "This is a test %d of this friday\n",$0}' file
This is a test 50 of this friday
This is a test 22 of this friday
This is a test 35 of this friday
This is a test 41 of this friday

关于python - 从行中搜索数字并放在特定句子中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16714012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com