python处理的例子

例子一(咖啡列表的处理)

coffee_list = [ '32Latte', '_Americano30','/34Cappuccino', 'Mocha35']

输出为:
1 Latte
2 Americano
3 Cappuccino
4 Mocha

def clean_list(lst):
    cleaned_list = []
    for item in lst:
        for c in item:
            if c.isalpha() != True:
                item = item.replace(c,'')
        cleaned_list.append(item)
    return cleaned_list
coffee_list = [ '32Latte', '_Americano30','/34Cappuccino', 'Mocha35']
cleaned_list = clean_list(coffee_list)
for k, v in zip(range(1, len(cleaned_list)+1),cleaned_list):
    print(k, v)

# 输出: 1 Latte
#	2 Americano
#	3 Cappuccino
#	4 Mocha

两个循环,第一个循环是列表,第二个循环是字符串。

item='32Latte'
for c in item:
        if c.isalpha() != True:
            item = item.replace(c,'')
print(item)
# print(c)

# 输出  Latte

你可能感兴趣的:(python学习基础内容,python,linux,开发语言)