Advertisement
Aikiro42

Untitled

Jan 26th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 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() or string[i] == ' ':
  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. print('STEP 1: {}'.format(step1))
  42.  
  43. # step1 = ' '.join(step1)  # since step1 is a string
  44. step2 = ''
  45. for char in step1:
  46.     # if char.isalpha():  # you can lowercase numbers, don't worry
  47.         # if char in 'aeiouAEIOU':
  48.         if char.lower() in 'aeiou':  # more efficient
  49.             step2 += char.upper()
  50.         else:
  51.             step2 += char.lower()
  52.     # else:
  53.         # step2 += char
  54. print('STEP 2: ', step2, sep='')
  55.  
  56. # step3a = []
  57. # step3b = []
  58. # Stick to proper naming conventions
  59. odd_words = []
  60. even_words = []
  61. step2 = step2.split(' ')
  62. # for word in step2:
  63. for i in range(len(step2)):  # easier
  64.     # if step2.index(word) % 2 == 0:
  65.     word = step2[i]
  66.     if i % 2 == 0:
  67.         oddw = ''
  68.         # for c in list(word):
  69.         for j in range(len(word)):
  70.             # if list(word).index(c) % 2 == 0:
  71.             if j % 2 == 0:
  72.                 # oddw += c
  73.                 oddw += word[j]
  74.         # step3a.append(oddw)
  75.         odd_words.append(oddw)
  76.     else:
  77.         # step3b.append(word[len(word)//2:])
  78.         even_words.append(word[len(word)//2:])
  79.  
  80. # print('STEP 3: ', ' '.join(step3a), '#', ' '.join(step3b), sep='')
  81. print('STEP 3: {}#{}'.format(' '.join(odd_words), ' '.join(even_words)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement