Python
Run Python : http://python.jsrun.net/
# coding:utf-8 #JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 from collections import OrderedDict print("Hello JSRUN! \n\n - from Python .") # 1 遍历 test_list = [1,3,5,6,3,5,6,7,8] print("original : " + str(test_list)) res = [] for i in test_list: if i not in res: res.append(i) print("ordered1 : " + str(res)) # 2 使用 set() test_list = list(set(test_list)) print("ordered2 : " + str(test_list)) # 3 使用列表理解 + enumerate() res=[] res = [i for n, i in enumerate(test_list) if i not in test_list[:n]] print("ordered3 : " + str(res)) # 4 使用 collections.OrderedDict.fromkeys() test_list=[2,2,2,2,2,2,3] res = list(OrderedDict.fromkeys(test_list)) print("ordered4 : " + str(res)) # 列表理解 res = [] res = [n for n in range(1, 21) if n%2==0] print("列表理解1 : "+str(res)) res = [n for n in range(1, 21)] print("列表理解2 : "+str(res)) res = [n**2 for n in range(1, 21) if n%2==0] print("列表理解3 : "+str(res)) res = [n**2 for n in range(1, 21)] print("列表理解4 : "+str(res))
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号