Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import string, itertools
  2.  
  3. def check_input(input):
  4.     if len(input) != 5:
  5.         return False
  6.     elif input[0] != '{':
  7.         return False
  8.     elif input[-1] != '}':
  9.         return False
  10.     elif input[1] not in string.ascii_letters:
  11.         return False
  12.     elif input[2] not in string.ascii_letters:
  13.         return False
  14.     elif input[3] not in string.ascii_letters:
  15.         return False
  16.     else:
  17.         return True
  18.  
  19. def main():
  20.     while True:
  21.         input = raw_input('Enter input in format {XYZ}: ')
  22.         result = []
  23.  
  24.         if check_input(input):
  25.             perm = input[1:4]
  26.             all_perms = itertools.permutations(perm)
  27.             for i in range(6):
  28.                 tuple = all_perms.next()
  29.                 joined = tuple[0] + tuple[1] + tuple[2]
  30.                 result.append(joined)
  31.  
  32.             joined_string = string.join(result, ', ')
  33.             print '{' + joined_string + '}'
  34.         else:
  35.             print 'incorrect format. try again'
  36.  
  37. if __name__ == '__main__':
  38.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement