列表 字符串 练习题

奇数索引位元素构成新列表

def func(lst):
    return lst[1::2]


lst = [1, 2, 3, 4, 5, 6, 7, 8]
print(func(lst))

 

 

 

li = ['taibal', 'alexC', 'ABC', 'egon', 'Ritian', 'Wusir', '  aqc']
lst = []
for el in li:
    if el.strip().endswith("c") and el.strip().upper().startswith("A"):
        lst.append(el)
print(lst)

 

posted @ 2020-05-04 22:59  CherryYang  阅读(113)  评论(0)    收藏  举报