给定列表如下:
l3=['AI','julyedu.com','caffe','AI','sklearn','AI','julyedu','Tensroflow','sklearn','keras','CNN','propont','NEXT','amazon aws']
1、使用循环
l3=['AI','julyedu.com','caffe','AI','sklearn','AI','julyedu','Tensroflow','sklearn','keras','CNN','propont','NEXT','amazon aws'] for item in l3: if len(item)>6: print(item)
输出:
1. julyedu.com 2. sklearn 3. julyedu 4. Tensroflow 5. sklearn 6. propont 7. amazon aws
2、使用列表推倒式
l4=['AI','julyedu.com','caffe','AI','sklearn','AI','julyedu','Tensroflow','sklearn','keras','CNN','propont','NEXT','amazon aws'] print([item for item in l4 if len(item)>6])
输出:
['julyedu.com', 'sklearn', 'julyedu', 'Tensroflow', 'sklearn', 'propont', 'amazon aws']