Advertisement
Aikiro42

Untitled

Jan 26th, 2020
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 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 it's the substring '12'
  22. if i + 1 < len(string):
  23. if string[i] == '1' and string[i + 1] == '2': # current string is '1', next string is '2'
  24. step1 += string[i]
  25. if 0 < i - 1:
  26. if 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. print(step2)
  63. # for word in step2:
  64. i = 0
  65. while i < len(step2): # easier
  66. # if step2.index(word) % 2 == 0:
  67. word = step2[i]
  68. if word == '':
  69. del step2[i]
  70. else:
  71. if i % 2 == 0:
  72. oddw = ''
  73. # for c in list(word):
  74. for j in range(len(word)):
  75. # if list(word).index(c) % 2 == 0:
  76. if j % 2 == 0:
  77. # oddw += c
  78. oddw += word[j]
  79. # step3a.append(oddw)
  80. odd_words.append(oddw)
  81. else:
  82. # step3b.append(word[len(word)//2:])
  83. even_words.append(word[len(word)//2:])
  84. i += 1
  85.  
  86. # print('STEP 3: ', ' '.join(step3a), '#', ' '.join(step3b), sep='')
  87. print('STEP 3: {}#{}'.format(' '.join(odd_words), ' '.join(even_words)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement