Advertisement
Aikiro42

abet_1c

Jan 26th, 2020
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. import sys
  2.  
  3. string = input()
  4. if len(string) == 0:
  5.     print('COMPRESSION FAILED')
  6.     sys.exit()
  7.  
  8. # step1 = []
  9. step1 = ''
  10. # for word in string.split(' '):  // I recommend you don't split the string immediately
  11. for i in range(len(string)):  # For each character in string
  12.     # if '12' in word:
  13.     #     twelve = ''
  14.     #     f = word.find('12')
  15.     #     twelve += (list(word).pop(f) + list(word).pop(f+1))
  16.     #     step1.append(twelve)
  17.     # The instructions state that you should just include the string '12' and all alpha characters
  18.     if string[i].isalpha():
  19.         step1 += string[i]  # add character to step1 if it's alphanumeric
  20.     else:
  21.         if 0 < i - 1 < i + 1 < len(string):  # if it isn't the end or beginning of the string
  22.                                              # also prevents IndexError from occuring
  23.             # if it's the substring '12'
  24.             if string[i] == '1' and string[i + 1] == '2': # current string is '1', next string is '2'
  25.                 step1 += string[i]
  26.             elif string[i] == '2' and string[i - 1] == '1':  # current string is '2', prev string is '1'
  27.                 step1 += string[i]
  28.  
  29.     # else:
  30.     #     alpha = ''
  31.     #     for c in word:
  32.     #         if c.isalpha():
  33.     #             alpha += c
  34.     #     if len(alpha) > 0:
  35.     #         step1.append(alpha)
  36.  
  37. if len(step1) == 0:
  38.     print('COMPRESSION FAILED')
  39.     sys.exit()
  40. print('STEP 1: ',' '.join(step1), sep='')
  41.  
  42. # step1 = ' '.join(step1)  # since step1 is a string
  43. step2 = ''
  44. for char in step1:
  45.     # if char.isalpha():  # you can lowercase numbers, don't worry
  46.         # if char in 'aeiouAEIOU':
  47.         if char.lower() in 'aeiou':  # more efficient
  48.             step2 += char.upper()
  49.         else:
  50.             step2 += char.lower()
  51.     # else:
  52.         # step2 += char
  53. print('STEP 2: ', step2, sep='')
  54.  
  55. # step3a = []
  56. # step3b = []
  57. # Stick to proper naming conventions
  58. odd_words = []
  59. even_words = []
  60. step2 = step2.split(' ')
  61. # for word in step2:
  62. for i in range(len(step2)):  # easier
  63.     # if step2.index(word) % 2 == 0:
  64.     word = step2[i]
  65.     if i % 2 == 0:
  66.         oddw = ''
  67.         # for c in list(word):
  68.         for j in range(len(word)):
  69.             # if list(word).index(c) % 2 == 0:
  70.             if j % 2 == 0:
  71.                 # oddw += c
  72.                 oddw += word[j]
  73.         # step3a.append(oddw)
  74.         odd_words.append(oddw)
  75.     else:
  76.         # step3b.append(word[len(word)//2:])
  77.         even_words.append(word[len(word)//2:])
  78.  
  79. # print('STEP 3: ', ' '.join(step3a), '#', ' '.join(step3b), sep='')
  80. print('STEP 3: {}#{}'.format(' '.join(odd_words), ' '.join(even_words)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement