|
| 1 | +# functions to sort out data |
| 2 | +# they act on lists |
| 3 | +# you can apply these functions in your programs |
| 4 | + |
| 5 | +# this function takes first and second element from list and compare them |
| 6 | +def bubbleSort(g): # g argument is for list |
| 7 | + for x in range(len(g) - 2): |
| 8 | + a = g[x] |
| 9 | + b = g[x + 1 + 1] |
| 10 | + if a > b : |
| 11 | + return(a) |
| 12 | + else : |
| 13 | + return(b) |
| 14 | +# use this to convert output into list |
| 15 | +# result = list(map(bubbleSort , g)) replace g with parameter |
| 16 | + |
| 17 | +# this function checks even num |
| 18 | +def oddSort(odd):# odd can be list or variable |
| 19 | + for x in odd: |
| 20 | + if x % 3 == 0: |
| 21 | + return(x) |
| 22 | +# use this to get list as output |
| 23 | +# result = list(filter(oddSort , odd)) replace odd with parameter |
| 24 | + |
| 25 | +# this function checks even num |
| 26 | +def evenSort(eve):# eve can be list or variable |
| 27 | + for a in eve: |
| 28 | + if a % 2 == 0: |
| 29 | + return(a) |
| 30 | +# use this to get list as output |
| 31 | +# result = list(filter(evenSort , eve)) replace eve with parameter |
| 32 | + |
| 33 | +# this function checks divisibility |
| 34 | +def divisibleSort(divi , get):# here divi is list and get is an variable set to integer or float |
| 35 | + for r in divi: |
| 36 | + if r % get == 0: |
| 37 | + return(r) |
| 38 | +# use this to get output |
| 39 | +# result = list(filter(divisibleSort , divi , get)) replace arguments with suitable parameters |
| 40 | + |
| 41 | +# this function checks if addition of group of two elements has desired answer |
| 42 | +def addBubbleSort(f,user):# here f is list and user is integer or float |
| 43 | + for x in range(len(f) - 2): |
| 44 | + a = f[x] |
| 45 | + b = f[x + 1 + 1] |
| 46 | + if a + b == user: |
| 47 | + return(a,b) |
| 48 | +# i havent checked this function check for bugs |
| 49 | +# this is how it works |
| 50 | +# res = list(filter(addBubbleSort , f , user)) replace arguments with suitable parameters |
| 51 | + |
| 52 | +# this function checks if subtraction of group of two elements has desired answer |
| 53 | +def subBubbleSort(z,userSub): |
| 54 | + for x in range(len(z) - 2): |
| 55 | + a = z[x] |
| 56 | + b = z[x + 1 + 1] |
| 57 | + if a - b == useSubr: |
| 58 | + return(a,b) |
| 59 | +# i havent checked this function check for bugs |
| 60 | +#res = list(filter(subBubbleSort , z , userSub)) replace arguments with suitable parameters |
0 commit comments