Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def countDigAndChar(lst):
- nums = 0
- chars = 0
- for e in lst:
- if type(e) is int:
- nums += 1
- else: # it should be char then
- chars += 1
- return (nums, chars)
- def identifySublist(digitCharList):
- size = len(digitCharList)
- for l in range(size, 1, -1):
- for i in range(0, size - l):
- nums, chars = countDigAndChar(digitCharList[i:l])
- if nums == chars:
- #print(nums, chars)
- #print(digitCharList[i:l])
- return i, l - i
- return None, None
- inp = [0, 'a', 'c', 4, 1, 2, 'b', 0, 2, 3]
- print(identifySublist(inp))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement