```if-not:javascript,python
Write function `parseFloat` which takes an input and returns a number or `Nothing` if conversion is not possible.
```

```if:python
Write function `parse_float` which takes a string/list and returns a number or 'none' if conversion is not possible.
```

```if:javascript
Write function `parseF` which takes an input and returns a number or null if conversion is not possible. The input can be one of many different types so be aware.
```

Difficulty: introductory

Starter code:

def parse_float(string):
	

Solutions:
def parse_float(string):
    try:
        return float(string)
    except:
        return None

def parse_float(string):
    try:
        return float(string)
    except (ValueError, TypeError):
        return None

def parse_float(string):
    try:
        return float(string)
    except:
        pass

def parse_float(s):
    try:
        return float(s)
    except:
        pass

def parse_float(s):
    if type(s) == str and __import__('re').match(r'[\d\.]+', s): return float(s)

def parse_float(s):
    try:
        return float(s)
    except (ValueError, TypeError):
        return None

def parse_float(string):
    return float(string) if type(string) is str and '.' in string else None

parse_float = lambda x, y=exec("def f(s):\n try:\n  return float(s)\n except:  return None"): f(x)

def parse_float(string):
    try:
        conv = float(string)
        return conv
    except:
        return None

def parse_float(string):
    try:
        float(string) 
    except (ValueError, TypeError):
        return None
    return float(string)


def parse_float(string):
    try:
        # Only runs if conversion is possible
        return float(string)
    except:
        return None

def parse_float(string):
    for char in string:
        if(not char.isnumeric() and char != "."):
            return None
    if("." in string):
        return float(string)
    return None

def parse_float(string):
    try:
        return float(string)
    except:
        return

def parse_float(string):
    try:
        return float(string)
    except (ValueError, TypeError):
        return

def parse_float(string):
    if isinstance(string,str):
        stringList = string.split('.')
        if len(stringList) == 2 and all(x.isdigit for x in stringList):
            return float(stringList[0]+'.'+stringList[1])
        else:
            return None
    else:
        return None

def parse_float(string):
    return float(string) if str(string).replace('-', '').replace('.', '').isdecimal() else None

def parse_float(string):
    return float(string) if isinstance(string,str) and not string.isalnum() else None

# https://habrastorage.org/webt/xt/af/nj/xtafnjpq-xw3lu0aisu68q22elg.png
from re import findall

def parse_float(string):
    if isinstance(string, str) and findall(r'[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?', string):
        return float(string)

def parse_float(str):
    try:
        return float(str) # why does float(str) work but not int(str)?
    except (TypeError, ValueError):
        return

import re

def parse_float(string):
    return float(string) if type(string) == str and re.match(r'\d+\.\d+$', string) else None

def parse_float(original):
    string = ''.join(original)
    try: return float(string)
    except: return None

def parse_float(string):
    try:
        a = float(string)
    except:
        return None
    return a

def parse_float(s):
    try:
        return float(s)
    except SyntaxError:
        return None
    except ValueError:
        return None
    except TypeError:
        return None

def parse_float(string):
    string = str(string)
    try:
        float(string)
            
        return float(string)
    
    except ValueError:
        
        return None

# the obvious approach...
def parse_float(string):
    try: return float(string)
    except ValueError: return None
    
# hand rolled
def parse_float(string):
    try:
        whole, fractional = string.split(".", maxsplit=1)
    except:
        return None        
    
    if not all(d.isdigit() for d in whole) or \
       not all(d.isdigit() for d in fractional):
        return None
    
    whole = sum(int(val)*10**place for place, val in enumerate(whole[::-1]))
    fractional = sum(int(val)*10**-(place+1) for place, val in enumerate(fractional))
    
    return whole+fractional

def parse_float (n): 
    try:
        if float(n):
            return float(n)
    except:
        return None


def parse_float(string: str) -> float:
    if type(string) == list:
        return None
    try:
        return float(string)
    except ValueError:
        return None

def parse_float(string):
    try:
        return float(str(string))
    except ValueError:
        return

def parse_float(string):
    try:
        if type(string) == list:
            for i in range(len(string)):
                string[i] = float(string[i])
            return string
        return float(string)
    except ValueError:
        return None

def parse_float(string):

    if type(string) == str:
        try:
            float(string)
            return float(string)
        except ValueError:
            return None


def parse_float(string):
    try:
        if type(string) == str:
            return float(string)
        if type(string) == list: 
            pass
    except ValueError:
        pass


def parse_float(string):
    try:
        float(string)
        if True:
            return float(string)
    except:
        return (None)

def parse_float(string):
    print(string)
    return None if type(string)==list else float(string) if "." in string else None

def parse_float(string):
    try: 
        num =  float(string)
        return num
    except:
        return 

def parse_float(string):
    try:
        if float(string)>0 or float(string)<0:
            return float(string)
    except:
        return None

def parse_float(string):    
    return float(''.join(string)) if ''.join(''.join(string).split('.')).isdigit() else None

def parse_float(string):
    if isinstance(string, str):
        if string.isalpha():
            return None
        return float(string)


def parse_float(string):
    try:
        x = float(string)
    except:
        return None
    return x

def parse_float(string):
    if type(string) == str:
        split_string = string.split(".")
        new_string = "".join(split_string)
        if new_string.isdigit():
            return float(string)
        else:
            return None
    elif type(string) == list:
        new_list = "".join(string)
        if new_list.isdigit():
            return float(string)
        else:
            return None
    else:
        pass

def parse_float(string):

    if isinstance(string, str):
        return float(string) if string.replace(".", "", 1).isdigit() else None
    else:
        return None

def parse_float(string):
    x = [string]
    for item in x:
        try:
            return float(item)
        except:
            return

def parse_float(string):
    if type(string) == list:
        separator = ','
        new_string = separator.join(string)
        string = new_string
    try:
        to_int = float(string)
        return to_int
    except ValueError:
        return None


def parse_float(string):
    try:
        x = float(string)
        return x
    except ValueError:
        return None
    except TypeError:
        try:
            y = float(''.join(string))
            return y
        except ValueError:
            return None
        

            



def parse_float(string):
    try:
        float(string) >= 0
        return float(string)
    except:
        return None

def parse_float(string):
    try:
        string = float(string) + 1 - 1
    except:
        return None
    return string

def parse_float(string):
 return None if any(i.isalpha() for i in string) else float(string)

import re


def parse_float(string):
    if not isinstance(string, str):
        return None 
    
    res = re.match(r'[0-9.]+', string)
    return float(res.group()) if res else None

def parse_float(string=None):
    try:
        s = float(string)
        return s
    except ValueError:
        return None
    except TypeError:
        return None


def parse_float(st):
    for i in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':
        if i in st or type(st) == list:
            return None
        else:
            return float(st)

def parse_float(string):
    flag = False
    for ch in string:
        if(((ord(ch) >= ord('0')) and (ord(ch) <= ord('9'))) or (ord(ch) == ord('.'))):
            flag = True
        else:
            flag = False
            break
    if(flag):
        return float("".join(string))
    else:
        return None

def parse_float(string):
    if type(string) == list:
        return None
    if string.isalpha():
        return None
    if float(string):
        return float(string)
    return -1

def parse_float(string):
    for i in ''.join(string): 
        if i in 'abcdefghijklmnopqrstuvwxyz': return None
    return float(''.join(string))

def parse_float(string):
    try:
        st = float(string)
        return st
    except: 
        None

def parse_float(string):
    try :
        a = eval(string)
    except :
        a = None
    return a

def parse_float(string):
    
    try:
        return float(string)
    
    except:
        return None
    
   # return float(string) or None


parse_float = lambda string: None if not all(c.isdigit() or c=='.' for c in string) else float(string)

def parse_float(string):
    string = str(string)
    try: 
        x = float(string)
        return x
    except ValueError:
        return None

def parse_float(x):
    try:
        return float(x)
    except:
        return None
            


def parse_float(string):
    for i in string:
        if i not in "0.123456789":
            return None
    return float(string)

def parse_float(string):
    try:
        if type(string) is list:
          return float(''.join(string))
        else:
            return float(string)
    except ValueError:
       return None

def parse_float(ts):
    try:
      float(ts)
      return float(ts)
    except:
      return None

def parse_float(string):
    return float(string) if type(string) == str and string.replace('.', '').replace('-', '').isdigit() else None

def parse_float(string):
    
    try:
        float(str(string))
        return float(string)
    except ValueError:
        return None

def parse_float(string):
    for e in string:
        c=ord(e)
        if c==46 or (c>47 and c<58):pass
        else:return None
    return float(string)

def parse_float(string):
    string = ''.join(string)
    if string.replace(".", "").isdigit():
        return float(string)
    return None

def parse_float(string):
    
    try:
        return float(string)
    except:
        return None




    #try:
        #return float(string)
    #except ValueError:
        #return None


def parse_float(string):
    try:
        return float(string)
    except:
        print(EnvironmentError)

def parse_float(x):
    try:
        return float(x)
    except:
        None


def parse_float(string):
    if not all(c.isdigit() or c == '.' for c in string):
        return None
    if (not '.' in string):
        return int(string)
    return float(string)

def parse_float(string):
    if type(string) == str:
        return None if string.isalpha() else float(string)
    else:
        set = ''
        num = set.join(string)
        return None if not num.isnumeric() else num

"""A primitive parser based on Haskell's Text.ParserCombinators.ReadP
This is super complicated don't do this"""
from operator import methodcaller


def parse_float(string):
    if isinstance(string, list):
        string = "".join(string)
    p = NumParser(string)
    res = p.parse_float()
    p.eof()
    if p.failed:
        return None
    return res

class Parser(object):
    """Base parser class
    Meant to be inherited by other classes

    TODO:
        - Implement `try`
        - Implement some sort of Applicative (especially Alternative <|>)
        - if self.failed == True, should halt any parsing
        -   You shouldn't need to constantly check for failure
    """
    def __init__(self, string):
        self.string = string
        self.failed = False

    def __repr__(self):
        return f"{self.__class__.__name__}({self.string}, {self.failed})"

    # primitive combinators
    def look(self):
        """Returns a copy of self (with new_parser.failed == True)
        For running a parser without affecting self
        """
        return type(self)(self.string)

    def get(self):
        """Gets the first character of the string"""
        if len(self.string) == 0 or self.failed:
            self.failed = True
            return None
        char = self.string[0]
        self.string = self.string[1:]
        return char

    def eof(self):
        """Succeeds iff there is no more string to consume"""
        if self.failed:
            return None
        self.failed = len(self.string) > 0
    
    def satisfy(self, func):
        """Consumes and returns the next character, if it satisfies the specified predicate
        func :: char -> bool
        """
        char = self.get()
        if self.failed:
            return None
        res = func(char)
        if isinstance(res, bool) and res:
            return char
        self.string = char + self.string
        self.failed = True
        return None

    def option(self, default, methodname, *args, **kwargs):
        """Will either parse self.methodname(*args, **kwargs) or return default on failure
        If failure, does not consume any characters, and self.failed remains as it was before
        e.g.,
        self = Parser("hi")
        1. self.option("c", "satisfy", str.islower) -> "h"
        2. self.option("c", "satisfy", str.isupper) -> "c"
        """
        looker = self.look()
        func = methodcaller(methodname, *args, **kwargs)
        func(looker)
        if looker.failed:
            return default
        return func(self)

    def char(self, character, insensitive=False):
        """self.char(character) == self.satisfy(ch.__eq__)
        self.char(character, insensitive=True) == self.satisfy(lambda x: x.casefold() == character.casefold())
        """
        if insensitive:
            return self.satisfy(lambda x: x.casefold() == character.casefold())
        return self.satisfy(character.__eq__)

    # more complex calls
    def many(self, methodname, *args, **kwargs):
        """Will parse while predicate holds true
        Returns list of results of predicate
        Never fails (can return [])
        """
        func = methodcaller(methodname, *args, **kwargs)
        results = []
        while not self.failed:
            res = func(self)
            if self.failed:
                self.failed = False # can be dangerous if you don't know what previous state was?
                break
            results.append(res)
        return results

    def many1(self, methodname, *args, **kwargs):
        """Same as many but requires at least one success"""
        func = methodcaller(methodname, *args, **kwargs)
        res = func(self)
        if self.failed:
            return None
        results = [res]
        results.extend(self.many(methodname, *args, **kwargs))
        return results

class NumParser(Parser):
    """A basic example of a Parser subclass
    Parses numbers (ints and floats)
    """
    def parse_int(self, signed=True):
        """Parses an integer
        If signed is True, allows a leading (-), otherwise it doesn't
        """
        sign = -1 if signed and self.option("+", "char", "-") == "-" else 1
        digits = self.many1("satisfy", str.isdigit)
        if self.failed:
            return None
        return sign * int("".join(digits))

    def parse_float(self):
        """Parses floats"""
        intpart = self.parse_int()
        if self.failed: # need a failure check here because sign requires intpart to exist
            return None
        sign = -1 if intpart < 0 else 1
        self.option(None, "char", ".")
        floatpart = self.option(["0"], "many1", "satisfy", str.isdigit)
        floatpart = int("".join(floatpart)) / 10**(len(floatpart))
        if self.option(None, "char", "e", insensitive=True) is not None:
            exppart = self.parse_int()
        else:
            exppart = 0
        if self.failed:
            return None
        return (intpart + sign * floatpart) * 10**exppart


def parse_float(string=""):
    try:
        float(string)
        return float(string)
    except:
        return None

def parse_float(string):
    string_new = "".join(string)
    try:
        float(string_new)
    except ValueError:
        return None
    return float(string_new)
    pass

def parse_float(string):
    if type(string) == list:
        try:
            return [float(i) for i in string]
        except ValueError:
            return None
    else:
        try:
            return float(string)
        except ValueError:
            return None

def parse_float(string):
    try:
        a = float(string)
        return a
    except (ValueError, TypeError):
        return None

def parse_float(string):
    try:
        return float(string)
    except:
        return None
    
parse_float("string")

def parse_float(string):
    try:
        i = float(string)
        return i 
    except:
        pass

def parse_float(string):
    string="".join(string)
    while True:
        try:
            return float(string)
        except ValueError:
            return None

def parse_float(string):
    try:
        return float(string)
    except ValueError as ex:
        return None
    except TypeError as xe:
        return None


def parse_float(string):
    lst = []
    if type(lst)==type(string):
        return None
    elif("a"<=string[0]>="z")or("A"<=string[0]>="A"):
        return None
    else:
        return float(string)


def parse_float(string):
    print(string)
    try : return float(string)
    except TypeError: 
        return None if None in [parse_float(x) for x in string] else [parse_float(x) for x in string]
    except ValueError: return None

def parse_float(string):
    return None if len([c for c in string if c not in ".0123456789"]) else float(string)

def parse_float(string):
    try: 
        if type(string) == list:
            string = ''.join(string)
        return float(string)
    except ValueError: 
        return None

def parse_float(string):
    arr = []
    if isinstance(string, list): 
        for x in string:
            try:
                arr.append(float(x))
            except ValueError:
                return None
        return arr
        
    try:
        return float(string)
    except ValueError:
        return None

def parse_float(string):
    if type(string) == list:
        string = "".join([ele for ele in string])
    try:
        return float(string)
    except ValueError:
        return None

def parse_float(string):
    if type(string)== list:
        for i in string:
            string = "".join(string)
    
    try:
        return float(string)
    except ValueError or TypeError:
        return None

def parse_float(string):
    for i in string:
        if i.isdigit() and type(string) is not list:
            return float(string)
        else:
            return None

def parse_float(string):

    try:
        result = float(string)
    except:

        return None

    else:

        return result


def parse_float(string):
    string = "".join(i for i in string)
    try:
        string = float(string)
        return string
    except ValueError:
        return None

def parse_float(string):
    try:
        f = float(string) if isinstance(string, str) else float("".join(string))
        return f
    except ValueError:
        return None


def parse_float(string):
    try:
        return None if not string.replace(".","").isdigit() else float(string)
    except:
        return None

def parse_float(value):
    try:
        float(value)
        return float(value)
    except:
        return None

parse_float("1")


def parse_float(string=''):
    try:
        return float(string)
    except:
        return None

def parse_float(string):
    if isinstance(string, list):
        string = "".join(string)
    try: 
        return float(string)
    except ValueError:
        return None


def parse_float(string):
    try:
        return float(str(string))
    except:
        return None

def parse_float(string):
    if isinstance(string,list) or string.isalpha():
        return None    
    return float(string)
    
    


def parse_float(string):
    string1 = ''.join(string)

    try:
        if isinstance(float(string1), float ):
            return float(string1)

    except ValueError:
        return None



def parse_float(string):
    try:
        if type(string) == list:
            return None
        else:
            floated_string = float(string)
            return floated_string
    except ValueError:
        return None


def parse_float(string):
    stuff = []
    blah = ''
    for i in string:
        if i in '0123456789.':
            stuff.append(i)
            blah = ''.join(stuff)
        else:
            return None
    return float(blah)

def parse_float(string):
    if isinstance(string,list) or string.isalpha():
        return None
    else:
        return float(string)