Py学习  »  Python

如何在python列表中只替换以某个字母开头的文本?

AAKASH IYER • 5 年前 • 1549 次点击  

我的问题与 excel formula to replace or stubstitute only text that starts with a certain letter 但我需要一个python代码。我正在尝试嵌套if,但它只替换第一个字符,而不是整个元素。

元素也是字母数字的

List= ['F43.9', 'F53.2', 'H10.9', 'H60.9', 
       'S83.6', 'S01.88', 'J18.9', 'K35.9', 'S42.20', 'J06.9'....]

所以我想要的结果是:

list=['qwe'、'qwe'、'equal'、'equal'、'chronic'、'chronic'、'responsible'、'priority'、'chronic'、'responsible'、…]

我需要用 F 例如 F43.9,F53.2,etc . 具有 "qwe" . 对于不同的字母也一样。列表中有30000个元素,具有600个唯一值。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44049
 
1549 次点击  
文章 [ 4 ]  |  最新文章 5 年前