Advertisement
edems96

cont

Mar 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. def countDigAndChar(lst):
  2.     nums = 0
  3.     chars = 0
  4.  
  5.     for e in lst:
  6.         if type(e) is int:
  7.             nums += 1
  8.         else: # it should be char then
  9.             chars += 1
  10.  
  11.     return (nums, chars)
  12.  
  13.  
  14. def identifySublist(digitCharList):
  15.     size = len(digitCharList)
  16.  
  17.     for l in range(size, 1, -1):
  18.         for i in range(0, size - l):
  19.             nums, chars = countDigAndChar(digitCharList[i:l])
  20.  
  21.             if nums == chars:
  22.                 #print(nums, chars)
  23.                 #print(digitCharList[i:l])
  24.                 return i, l - i
  25.  
  26.     return None, None
  27.  
  28.  
  29. inp = [0, 'a', 'c', 4, 1, 2, 'b', 0, 2, 3]
  30.  
  31. print(identifySublist(inp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement