Last active
          May 15, 2017 15:39 
        
      - 
      
- 
        Save Everfighting/8a4f32d992ef6df4ec078a799b7cd924 to your computer and use it in GitHub Desktop. 
    列表筛选
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from random import randint | |
| data = [randint(-10,10) for _ in range(10)] | |
| results = [x for x in data if x >= 0] | |
| # 列表解析的速度更快,用timeit测试 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from random import randint | |
| data = [randint(-10,10) for _ in range(10)] | |
| results = filter(lambda x: x>=0, data) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment