5/13/2016

UpPER anD LowEr CaSe

http://pastebin.com/2mHEYxRa

Simple Round Bracket Parsing

For round brackets:

 def RBP(expression):
    flag = 0
    for char in expression:
        if char == "(":
            flag -=1
        elif char == ")":
            if flag < 0:
                flag +=1
            else:
                return False
      
    if flag == 0:
        return True
    return False

5/07/2016

Greatest Common Divisor function with multiple arguments in python

import math 
import fractions
def gcdm(*args):
    UaS = sorted(list(set(list(args))))
    if len(UaS) == 1:
        return list(UaS)[0]
    if len(UaS) == 2:
        return fractions.gcd(UaS[0],UaS[1])
    if len(UaS) >= 3:
        pair = fractions.gcd(UaS[0],UaS[1])
        print(pair)
        for i in range(2,len(UaS)):
            pair = fractions.gcd(pair,UaS[i])
        return pair
    return 0
 
print(gcdm(10,20,30,40,50)) == 10

You can do it with fractions or math module which both have gcd function.

5/03/2016

Basic validating of the email address in python


I saw some regex strings for validing email address that I didn't fully understand so I tried to make it without regex. If I was to make regex for validating email it would look something like this:
re.compile("\w+@\w+[.][A-Za-z]{2,}", re.I | re.A)

Ah, well this is code I was working on:

https://pastebin.com/yiXM9p5a


 
If you need to test out some python code and you don't have python installed on computer but you have internet connection (that's fast enough) you can test your code here.

Links:
https://docs.python.org/3/howto/regex.html?highlight=regular%20expression - HOWTO: Regular Expression (Python)
https://repl.it/ - Online Python and more other languagues.
http://pastebin.com/vRPfSFyN (Until June 9th 2017)
http://pastebin.com/0BKrwwhT