我有一个无法解决的简单问题: 我有这样的字符串列表:
t = ['un1389 u1243 1522 1433 un1312','u1543 1423 1192 un1313','1762 1542 u1124']
您会注意到,某些字符串的开头包含一个带有“ un”符号的数字。 我要做的是摆脱'un'而不是'u'标志。 所以这是我正在做的不起作用的事情:
for i in t:
for j in i.split():
if j[0] == 'u' and j[1] == 'n':
j = j.translate({ord(j[0]:None)})
j = j.translate({ord(j[0]:None)})
#In the second line of the if condition I am using j[0] again because u has already been removed and
#n is
#0 now.
print(t)
#This gives me the original t without any changes!
预先感谢, 戴夫