Skip to content

Instantly share code, notes, and snippets.

@itzbernoulli
Last active October 10, 2016 20:33
Show Gist options
  • Save itzbernoulli/80fe4c0cce82b2fef9f35cd8cc40e726 to your computer and use it in GitHub Desktop.
Save itzbernoulli/80fe4c0cce82b2fef9f35cd8cc40e726 to your computer and use it in GitHub Desktop.
def sort_asc(arr):
for y in range(len(arr)-1,0,-1):
for x in range(y):
if arr[x]>arr[x+1]:
temp = arr[x]
arr[x] = arr[x+1]
arr[x+1] = temp
return arr
def sort_desc(arr):
for desc in range(len(arr)-1,0,-1):
for x in range(desc):
if arr[x]<arr[x+1]:
des = arr[x+1]
arr[x+1] = arr[x]
arr[x] = des
return arr
def weird_sort(nums):
new_array = []
# sort the array with the sort function
arr = sort_asc(nums)
# divide the array into two parts
first_halve = arr[0:int((len(arr)+1)/2)]
second_halve = arr[int((len(arr)+1)/2):]
# Put the first half into the rearranged array
second_halve = sort_desc(second_halve)
new_array = first_halve + second_halve
return new_array
a = [89,45,56,23,84,55,67,59,12,74]
print weird_sort(a)
def take_string(arr):
snake=""
for i in arr:
if (ord(i) >= 65) and (ord(i) <= 90):
if snake == "":
snake = snake + i.lower()
else:
snake = snake + "_" + i.lower()
else:
snake = snake + i
print snake
take_string("MyWords")
def sort(arr):
for y in range(len(arr)-1,0,-1):
for x in range(y):
if arr[x]>arr[x+1]:
temp = arr[x]
arr[x] = arr[x+1]
arr[x+1] = temp
return arr
arr = [54,26,93,17,77,31,44,55,20]
sorted = sort(arr)
print sorted
def pick_two(sorted_arr):
new = []
new = [sorted_arr[1],sorted_arr[-2]]
return new
print pick_two(sorted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment