Skip to content

Instantly share code, notes, and snippets.

@johnotu
Last active October 10, 2016 22:40
Show Gist options
  • Save johnotu/575fe462f86039a9d3725fabab2bac26 to your computer and use it in GitHub Desktop.
Save johnotu/575fe462f86039a9d3725fabab2bac26 to your computer and use it in GitHub Desktop.
# Class activity 1
def list_range(list_):
if len(list_) == 1:
return [list_[0]]
smallest = list_[0]
largest = list_[0]
for item in list_:
if item > largest:
largest = item
elif item < smallest:
smallest = item
return [smallest, largest]
# Class activity 2
def next_range(list_):
tmp_list = list_[:]
range_ = list_range(tmp_list)
tmp_list.remove(range_[0])
tmp_list.remove(range_[1])
return list_range(tmp_list)
# Class activity 3
def sort_asc_dsc(list_):
tmp_list = list_[:]
mid_list = len(tmp_list) / 2
sorted_ = []
i = 0
while i < mid_list :
range_ = list_range(tmp_list)
sorted_.insert(mid_list + i, range_[1])
sorted_.insert(i, range_[0])
tmp_list.remove(range_[0])
tmp_list.remove(range_[1])
i = i + 1
if len(tmp_list) == 1:
sorted_.insert(mid_list,tmp_list[0])
else:
pass
return sorted_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment