This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #sort playlist | |
| def sort_music_asc(a): | |
| i = 0 | |
| m = a[i][1] | |
| for m in range(len(a)-1,0,-1): | |
| for i in range(m): | |
| if a[i][1]>a[i+1][1]: | |
| temp = a[i] | |
| a[i] = a[i+1] | |
| a[i+1] = temp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def camel_snake(input): | |
| output = [input[0].lower()] | |
| for c in input[1:]: | |
| if c in ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'): | |
| output.append('_') | |
| output.append(c.lower()) | |
| else: | |
| output.append(c) | |
| return str.join('', output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sort_mylist_asc(a): | |
| for my_number in range(len(a)-1,0,-1): | |
| for i in range(my_number): | |
| if a[i]>a[i+1]: | |
| temp = a[i] | |
| a[i] = a[i+1] | |
| a[i+1] = temp | |
| return a | |
| def second_places(a): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sort_mylist_asc(a): | |
| for my_number in range(len(a)-1,0,-1): | |
| for i in range(my_number): | |
| if a[i]>a[i+1]: | |
| temp = a[i] | |
| a[i] = a[i+1] | |
| a[i+1] = temp | |
| return a | |
| def sort_mylist_desc(a): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def product_except?(d) | |
| e = [] | |
| startvalue = 0 | |
| endvalue = d.length | |
| product = d.inject(1){|first,n| first * n} | |
| result = [] | |
| while startvalue < endvalue | |
| result.push(product/ d[startvalue]) | |
| startvalue = startvalue + 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mid_point(x,y) | |
| (x+y)/2.0 | |
| end | |
| def square_root(x,e) | |
| if x == 1 | |
| guess = 1 | |
| else | |
| lowest = 0 | |
| highest = x | |
| guess = mid_point(lowest,highest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mid_point(x,y) | |
| (x+y)/2.0 | |
| end | |
| def square_root(x,e) | |
| if x==1; | |
| guess=1 | |
| else | |
| lowest = 0 | |
| highest = x | |
| guess = mid_point(lowest,highest) |
NewerOlder