lt = ['word',12,'hello',34,'by','whereyou'] f = filter(lambda x:type(x) == str,lt) lt1 = list(f) for i in range(len(lt1)-1): for j in range(len(lt1)-i-1): if len(lt1[j])<len(lt1[j+1]): lt1[j],lt1[j+1] = lt1[j+1],lt1[j] print(lt1)
# 1.传入一个列表,列表中元素可能是任意类型 # 2.使用高级函数完成非字符串元素的删除 # 3.然后按照字符串的长度进行降序排序 # 4.返回新的排序后的列表
最新推荐文章于 2021-11-07 00:29:25 发布