I want to for loop over a list of 14 items except for the last two items. Does anybody know if there is a function or command in python which accomplishes this?
            Asked
            
        
        
            Active
            
        
            Viewed 169 times
        
    -1
            
            
        - 
                    1Same logic as duplicate link, just change the `1` to `2`. – U13-Forward Sep 02 '21 at 08:20
3 Answers
1
            
            
        random_list = [1, 2, 3, 4, 5, 6]
for element in random_list[:-2]:
     print(element)
[Out] :
1 2 3 4
 
    
    
        Odhian
        
- 351
- 5
- 14
1
            
            
        optionally
items = [] # your 14 item long list here
for i in range(len(items)-2):
    print(items[i])
 
    
    
        Henok Teklu
        
- 528
- 3
- 9
 
     
    