Advertisement
IvaSerge

listFilterBySimmilar

Mar 13th, 2018
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import sys
  2. pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
  3. sys.path.append(pyt_path)
  4. import random
  5.  
  6. list1 = []
  7. list2 = []
  8. listLen_1 = random.randint(0,10)
  9. listLen_2 = random.randint(0,10)
  10. list1 = [random.randint(0,10) for r in xrange(listLen_1)]
  11. list2 = [random.randint(0,10) for r in xrange(listLen_2)]
  12.  
  13.  
  14. outlist = []
  15. #Найдем днинный список и первый цикл организовываем по длинному списку
  16. if len(list1) >= len(list2):
  17.     longList = list1
  18.     shortList = list2
  19. else:
  20.     longList = list2
  21.     shortList = list1
  22.  
  23.  
  24. for i in longList:
  25.     checkList = False
  26.     for j in shortList:
  27.         if i == j and i not in outlist: #проверка на дубликаты
  28.             checkList = i
  29.             break
  30.     outlist.append(checkList)
  31.    
  32. OUT = outlist, list1, list2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement