我正在寻找一种从同时具有大写字母和可能小写字母的字符串中获取小写值的方法
这是一个例子
sequences = ['CABCABCABdefgdefgdefgCABCAB','FEGFEGFEGwowhelloFEGFEGonemoreFEG','NONEARELOWERCASE'] #sequences with uppercase and potentially lowercase letters
这就是我想要输出的
upper_output = ['CABCABCABCABCAB','FEGFEGFEGFEGFEGFEG','NONEARELOWERCASE'] #the upper case letters joined together
lower_output = [['defgdefgdefg'],['wowhello','onemore'],[]] #the lower case letters in lists within lists
lower_indx = [[9],[9,23],[]] #where the lower case values occur in the original sequence
所以我希望 lower_output 列表是 SUBLISTS 的列表。SUBLISTS 将包含所有小写字母字符串。
我正在考虑使用正则表达式。. .
import re
lower_indx = []
for seq in sequences:
lower_indx.append(re.findall("[a-z]", seq).start())
print lower_indx
对于我尝试的小写列表:
lower_output = []
for seq in sequences:
temp = ''
temp = re.findall("[a-z]", seq)
lower_output.append(temp)
print lower_output
但这些值不在单独的列表中(我仍然需要加入它们)
[['d', 'e', 'f', 'g', 'd', 'e', 'f', 'g', 'd', 'e', 'f', 'g'], ['w', 'o', 'w', 'h', 'e', 'l', 'l', 'o', 'o', 'n', 'e', 'm', 'o', 'r', 'e'], []]