Advertisement
Guest User

Untitled

a guest
Dec 14th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. def get_pins(observed):
  2.     nums = []
  3.     keypad = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'], ['', '0', '']]
  4.     for elem in observed:
  5.         for number_list in keypad:
  6.             if elem in number_list:
  7.                 keys = ''
  8.                 keys += (''.join([number_list[i] for i in range(len(number_list))
  9.                 if i in range(number_list.index(elem)- 1, number_list.index(elem) + 2)]))
  10.                 keys +=(''.join([number_list_[number_list.index(elem)] for number_list_ in keypad
  11.                 if keypad.index(number_list_) in range(keypad.index(number_list) - 1, keypad.index(number_list) + 2) ]))
  12.                 nums.append(keys)
  13.     for i in range (len(nums)):
  14.         for elem in nums[i]:
  15.             if nums[i].count(elem) >= 2:
  16.                 nums[i] = nums[i].replace(elem, '', nums.count(elem) - (nums.count(elem)- 1))
  17.     result = []
  18.     if len(nums) == 1:
  19.         return [x for x in nums[0]]
  20.     else:
  21.         for num in nums[0]:
  22.             result_ = []
  23.             result_.append(num)
  24.             for i in range(1, len(nums)):
  25.                 result_ = ([num + x for num in result_ for x in nums[i]])
  26.             result.extend(result_)
  27.  
  28.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement