2022-10-20 21:22:14 +00:00
|
|
|
def main():
|
|
|
|
print(evenThenOdd('abcd'))
|
|
|
|
print(removeAdjacentDuplicates('mississipi'))
|
|
|
|
print(reapeatNumTimes(4))
|
|
|
|
print(positionOfFirstLargest([1, 624, 123, 34, 12]))
|
|
|
|
|
2023-01-30 16:48:43 +00:00
|
|
|
|
2022-10-20 21:22:14 +00:00
|
|
|
def evenThenOdd(string):
|
|
|
|
even = ''
|
|
|
|
odd = ''
|
2023-01-30 16:48:43 +00:00
|
|
|
for index, char in enumerate(string):
|
2022-10-20 21:22:14 +00:00
|
|
|
if index % 2 == 0:
|
|
|
|
even += char
|
|
|
|
else:
|
|
|
|
odd += char
|
|
|
|
return even + odd
|
|
|
|
|
|
|
|
|
|
|
|
def removeAdjacentDuplicates(s):
|
2022-11-10 23:20:38 +00:00
|
|
|
new = ''
|
|
|
|
for i in range(len(s)):
|
2023-01-30 16:48:43 +00:00
|
|
|
if i == 0 or s[i] != s[i-1]:
|
2022-11-10 23:20:38 +00:00
|
|
|
new += s[i]
|
|
|
|
return new
|
2022-10-20 21:22:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def reapeatNumTimes(n):
|
|
|
|
lst = []
|
2022-11-10 23:20:38 +00:00
|
|
|
for i in range(1, n+1):
|
2023-01-30 18:34:06 +00:00
|
|
|
lst += [i] * i
|
2022-10-20 21:22:14 +00:00
|
|
|
return lst
|
|
|
|
|
|
|
|
|
|
|
|
def positionOfFirstLargest(arr):
|
2023-01-30 16:48:43 +00:00
|
|
|
mx = arr[0]
|
2023-01-30 22:03:48 +00:00
|
|
|
index = 0
|
|
|
|
for i, a in enumerate(arr):
|
2022-10-20 21:22:14 +00:00
|
|
|
if a > mx:
|
|
|
|
mx = a
|
2023-01-30 22:03:48 +00:00
|
|
|
index = i
|
|
|
|
return index
|
2022-10-20 21:22:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-11-10 23:20:38 +00:00
|
|
|
main()
|