Complete the function/method so that it takes CamelCase string and returns the string in snake_case notation. Lowercase characters can be numbers. If method gets number, it should return string.

Examples:

``` javascript
//  returns test_controller
toUnderscore('TestController');

// returns movies_and_books
toUnderscore('MoviesAndBooks');

// returns app7_test
toUnderscore('App7Test');

// returns "1"
toUnderscore(1);
```

``` coffeescript  
#  returns test_controller
toUnderscore 'TestController'

# returns movies_and_books
toUnderscore 'MoviesAndBooks'

# returns app7_test
toUnderscore 'App7Test'

# returns "1"
toUnderscore 1
```

Difficulty: introductory

Starter code:

def to_underscore(string):
	

Solutions:
import re

def to_underscore(string):
    return re.sub(r'(.)([A-Z])', r'\1_\2', str(string)).lower()    


def to_underscore(string):
    string = str(string)
    camel_case = string[0].lower()
    for c in string[1:]:
        camel_case += '_{}'.format(c.lower()) if c.isupper() else c
    return camel_case

def to_underscore(string):
    return ''.join('_'+c.lower() if c.isupper() else c for c in str(string)).lstrip('_')

import re
def to_underscore(string):
    return re.sub("(?<=.)(?=[A-Z])","_",str(string)).lower()

import re


def to_underscore(string):
    try:
        return '_'.join(x.lower() for x in re.findall('[A-Z][^A-Z]*', string))
    except:
        return str(string)

def to_underscore(string):
    string = str(string)
    new = []
    for s in string:
        if not new:
            new.append(s)
        else:
            if s.isupper():
                new.append("_")
            new.append(s)
    return "".join(new).lower()


def to_underscore(s):
    if isinstance(s, (int, float)):
        return str(s)
    
    return ''.join([c if c == c.lower() else "_"+c.lower() for c in s ]).strip("_")

def to_underscore(s):   
    return "".join(["_" + c.lower() if c.isupper() else c for c in str(s)]).strip("_")

def to_underscore(xs):
    return ''.join(('_' if i and x.isupper() else '') + x.lower() for i, x in enumerate(str(xs)))