Advertisement
Aikiro42

timothy_1c

Jan 26th, 2020
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.49 KB | None | 0 0
  1. import sys  # helps in terminating the program
  2.  
  3. # a = input()
  4. # letters = []
  5. # for character in a:
  6. #     letters += character
  7. # Follow naming conventions.
  8. # You can also convert an input string to a list of characters by doing list(input())
  9. # but for this scenario it's more efficient to work with strings
  10. str_in = input()
  11. # s1 = []
  12. step1 = ''
  13. i = 0
  14. # while i < len(letters):
  15. while i < len(str_in):
  16.     # if letters[i] == '1' and letters[i + 1] == '2':
  17.     #     s1 += letters[i] + letters[i + 1]
  18.     #     i += 1
  19.     # elif letters[i].isalpha() == True or letters[i] == ' ':
  20.     #     s1 += letters[i]
  21.     #     i += 1
  22.     # else:
  23.     #     i += 1
  24.     # Best to start with adding alphas
  25.     if str_in[i].isalpha():
  26.         step1 += str_in[i]
  27.     else:
  28.         # Avoid IR with this
  29.         if i + 1 < len(str_in):
  30.             if str_in[i] == '1' and str_in[i+1] == '2':
  31.                 step1 += str_in[i] + str_in[i + 1]
  32.                 i += 1
  33.     i += 1
  34. # s1 = ''.join(s1)
  35.  
  36. # if s1 == '' or '12' not in s1:
  37. if len(step1.strip()) == 0:
  38.     print("COMPRESSION FAILED")
  39.     sys.exit()
  40.  
  41. step1_up = step1.upper()
  42. step2 = ''  # more efficient to work with strings
  43. # for letter in s1_up:
  44. #     step2 += letter
  45. # vowels = ['A', 'E', 'I', 'O', 'U']
  46. vowels = 'AEIOU'
  47. # conso = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z']
  48. # if a letter ain't a vowel, it's either a consonant or 1 or 2.
  49. # uppercasing a number yields no effect.
  50. # s2 = []
  51. # for y in step2:
  52. for y in step1_up:
  53.     # if y in vowels:
  54.     if y not in vowels:
  55.         # y = y.upper()
  56.         y = y.lower()
  57.         # step2.append(y)
  58.         step2 += y
  59.     # elif y in conso:
  60.     #     y = y.lower()
  61.     #     s2.append(y)
  62.     else:
  63.         # step2.append(y)
  64.         step2 += y  # no need to upper since you upper'd the whole string initially
  65. # s2 = ''.join(s2)
  66. # s2_2 = s2
  67. # step2 is complete and a string, prior two lines unnecessary
  68.  
  69. # if s2 == '' or '12' not in s2:
  70. if len(step2.strip()) == 0:
  71.     print("COMPRESSION FAILED")
  72.     sys.exit()
  73.  
  74. step2 = step2.split()
  75. odd = []
  76. even = []
  77. j = 0
  78. while j < len(step2):
  79.     word = step2[j]
  80.     if word == '':
  81.         del step2[j]
  82.         # no need to increment, len(step2) will decrease and list will shift left
  83.     else:
  84.         if j % 2 == 0:
  85.             # edit it now so all you have to do is join lists
  86.             n_word = ''
  87.             for k in len(word):
  88.                 if k % 2 == 0:
  89.                     n_word += word[k]
  90.  
  91.             odd.append(n_word)
  92.         else:
  93.             even.append(word[len(word)//2:])
  94.     j += 1  # bring out increment
  95.  
  96. # first_part = []
  97. # second_part = []
  98. # m = 0
  99. # while m < len(odd):
  100. #     n = 0
  101. #     while n < len(odd[m]):
  102. #         if n % 2 == 0:
  103. #             first_part.append(odd[m][n])
  104. #             if n == len(odd[m]) - 1 or n == len(odd[m]) - 2:
  105. #                 first_part.append(' ')
  106. #         n += 1
  107. #     m += 1
  108. # first_half = ''.join(first_part)
  109. # first_half = first_half.rstrip()
  110. #
  111. # for x in even:
  112. #     upper_half = (x[(len(x) // 2):])
  113. #     second_part.append(upper_half)
  114. #     second_part.append(' ')
  115. # second_half = ''.join(second_part)
  116. # hashtag = "#"
  117. # s3 = first_half + hashtag + second_half
  118. # no need for this part since we processed it while sorting the odds and evens
  119. step3 = '{}#{}'.format(' '.join(odd), ' '.join(even))
  120. if step3.strip() == '#':
  121.     print("COMPRESSION FAILED")
  122.     sys.exit()
  123.  
  124. print('STEP 3: {}'.format(step3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement