Example #1
0
def temNumero(frase):
    '''
    Recebe a frase e verifica se algum dos dígitos é um número, se for a variável num é True e entra no while.
    Continua no while até a frase não ter números
    Requires: frase seja string
    Ensures: return a frase sem números
    '''
    num = any(string.isdigit() for string in frase)
    while num == True:
        frase = input(
            "Escreva a frase que deseja traduzir apenas com letras: ")
        num = any(string.isdigit() for string in frase)
    return frase
Example #2
0
 def combinations(self, string):
     if not string.isdigit():
         for word in map(
                 ''.join,
                 itertools.product(*zip(string.upper(), string.lower()))):
             yield word
     yield string
Example #3
0
def get_color(string):
    if string == "":
        return discord.Color(0)
    elif string.startswith("0x"):
        try:
            return discord.Color(int(string[2:], 16))
        except:
            pass
    elif string.isdigit():
        try:
            return discord.Color(int(string))
        except:
            pass
    elif string in [
            "teal", "dark_teal", "green", "dark_green", "blue", "dark_blue",
            "purple", "dark_purple", "magenta", "dark_magenta", "gold",
            "dark_gold", "orange", "dark_orange", "red", "dark_red",
            "lighter_grey", "lighter_gray", "dark_grey", "dark_gray",
            "light_grey", "light_gray", "darker_grey", "darker_gray",
            "blurple", "greyple"
    ]:
        return getattr(discord.Color, string)()
    raise BotError(
        "Invalid color format; 0x<hexcode>, integer, or a Discord template color."
    )
Example #4
0
def is_digit(string):
    if string.isdigit():
        return True
    else:
        try:
            float(string)
            return True
        except ValueError:
            return False
Example #5
0
    def __isDigit(self, string) -> bool:
        if isinstance(string, str):
            if len(string) > 0:
                if string.isdigit():
                    return True
                if string[0] == '-' and string[1:].isdigit():
                    return True

        return False
Example #6
0
    def __init__(self, fnames, dummies=False, discretecutoff=10):
        self.fnames = fnames
        self.rawData = {}
        self.filedict = {}
        self.filedict['breast'] = open('BREAST.TXT', 'r')
        self.filedict['colrect'] = open('COLRECT.TXT', 'r')
        self.filedict['lymyleuk'] = open('LYMYLEUK.TXT', 'r')
        self.filedict['malegen'] = open('MALEGEN.TXT', 'r')
        self.filedict['respir'] = open('RESPIR.TXT', 'r')
        self.filedict['urinary'] = open('URINARY.TXT', 'r')
        self.filedict['femgen'] = open('FEMGEN.TXT', 'r')
        self.allfnames = [
            'breast', 'colrect', 'lymyleuk', 'malegen', 'respir', 'urinary',
            'femgen'
        ]
        self.dummies = dummies
        if fnames[0] == 'all':
            self.fnames = self.allfnames
            for name, f in self.filedict.items():
                self.rawData[name] = f.readlines()

        else:
            for name in fnames:
                if name not in self.allfnames:
                    print('FOUND INVALID FILENAME: ', name)
                    exit()
                self.rawData[name] = self.filedict[name].readlines()

        self.seerdictfile = open('seerdict.txt')

        self.dataPositionDict = {}
        self.featureList = []
        for line in self.seerdictfile:
            s = line.split(' ')
            start = [int(string) for string in s if string.isdigit()][0] - 1
            s2 = [string for string in s if 'char' in string][0]
            length = int(''.join(list(filter(str.isdigit, s2))))
            end = start + length
            label = ''
            if s[6] != '':
                label = s[6]
            elif s[7] != '':
                label = s[7]
            elif s[8] != '':
                label = s[8]
            self.dataPositionDict[label] = (start, end)
            self.featureList.append(label)
            self.featsFinalUsed = []
            self.discretecutoff = discretecutoff
def is_num(number):
    """
    判断是否为数字
    :param number:
    :return:
    """
    string = str(number)
    print("判断所有字符都是数字或者字母: ", string.isalnum())
    print("判断所有字符都是字母: ", string.isalpha())
    print("判断所有字符都是数字: ", string.isdecimal())
    print("判断所有字符都是数字: ", string.isnumeric())  # 此方法只针对unicode对象
    print("判断所有字符都是小写: ", string.islower())
    print("判断所有字符都是大写: ", string.isupper())
    print("判断所有字符都是空白符: ", string.isspace())
    return string.isdigit()
Example #8
0
def is_positive_number(string, neg=False):
    if not string:
        return False
    if string.isdigit():
        return True
    
    if "." in string:
        if string.startswith(".") OR string.endswith("."):
            return False
        elif len(string.split("."))>2:
            return False
        else:
            new_string="".join(string.split("."))
            if new_string.is_digit():
                return True
Example #9
0
def generate_alphanumerics():
    """Utilize uuid4, then stripping all "-" and slicing the string randomly
    Returns:
        string: an alphanumeric string
    """
    length_of_string = generate_random_integer(MIN_LENGTH_OF_ALPHANUMERIC,
                                               MAX_LENGTH_OF_ALPHANUMERIC)

    string = str(uuid4()).replace("-", "")[:length_of_string]

    # Handle case if the uuid output is not alphanumeric after slicing else just return
    if string.isdigit():
        return string + generate_alphabetical_strings()
    elif string.isalpha():
        return string + str(generate_random_integer(MIN_LENGTH, MIN_LENGTH))
    else:
        return string
Example #10
0
def is_notanitem(string):
    NOTITEM_STRINGS = ["sav", "fuel", "pnts", "points", "pts", "you",
                       "parti", "part", "prtic", "par", "for", "chg",
                       "chng", "chan", "svng", "svn", "svin", "amo",
                       "amount", "amt", "ouv", "ount", "f0r", "avin",
                       "rew", "wards", "war", "rewrds", "car", "wrds", "ward",
                       "ord", "orde", "sains", "cas", "cah", "cash",
                       "back", "bak", "refn", "refun", "rfnd", "refund", "fund",
                       "ttl", "valu", "value", "discount", "empl", "employee",
                       "loyal", "loy", "disc", "tax", "perc", "percent", "pct",
                       "bala", "baac", "ance", "rnce", "lnce", "cred", "crd", "deb",
                       "debit", "credit", "purch", "chas", "expi", "point", "visit",
                       "regis", "rgist", "limi", 'lmt', "code", "sku", "$", "pric",
                       "pri", "prc", "gal", "gas", "check", "bonu", "debi", "card"]
    if string.isdigit() or any([string.find(x) for x in NOTITEM_STRINGS]) > -1:
        return True
    else:
        return False
import string

from leetcode_combine_solutions.solutions_all_questions import Solutions

nums = [1, 2, 3, 4, 5]
for i in range(len(nums) - 1, -1, -1):
    print(nums[i])

string = "abab1"
print(str.isalpha(string))
print(string.isdigit())

for char in string:
    if char.isdigit():
        print(char)
Example #12
0
	def key_colon(self, edit, string):
		view = self.view
		window = view.window()
		sel = view.sel()
		line = None

		start = string[0]
		remains = string[1:]
		if start in ('+', '-') and remains.isdigit():
			view.run_command('single_selection')
			line = view.rowcol(sel[0].a)[0]
			shift = int(remains)

			if start == '+': line += shift
			else: line -= shift
		
		elif string == '$':
			line = view.visible_region().b

		elif string.isdigit():
			line = max(int(string) - 1, 0)

		elif string == 'w':
			self.save()

		elif string == 'wq':
			view.run_command('save')
			window.run_command('close')
		
		elif string == 'q!':
			if view.is_dirty():
				view.run_command('revert')
			
			window.run_command('close')

		elif string == 'q':
			if not view.is_dirty():
				window.run_command('close')
		
		elif string == 'x':
			if view.is_dirty():
				view.run_command('save')
			
			window.run_command('close')
		
		elif string == 'n':
			window.run_command('next_view')
		
		elif string == 'N':
			window.run_command('prev_view')

		if line != None:
			point = view.text_point(line, 0)
			
			sel.clear()
			line = view.line(point)

			cur = sublime.Region(line.a, line.a)
			sel.add(cur)

			view.show(sel)
Example #13
0
def Format(string, length):
    spaces = ' ' * (length - len(string))
    if string.isdigit():
        return spaces + string
    else:
        return string + spaces
Example #14
0
def get_numbers_from_date_string(date_string):
    splitted_date = [
        string for string in date_string.split() if string.isdigit()
    ]
    return splitted_date
Example #15
0
    def key_colon(self, edit, string):
        view = self.view
        window = view.window()
        sel = view.sel()
        line = None

        start = string[0]
        remains = string[1:]
        if start in ('+', '-') and remains.isdigit():
            view.run_command('single_selection')
            line = view.rowcol(sel[0].a)[0]
            shift = int(remains)

            if start == '+': line += shift
            else: line -= shift

        elif string == '$':
            line = view.visible_region().b

        elif string.isdigit():
            line = max(int(string) - 1, 0)

        elif string == 'w':
            self.save()

        elif string == 'wq':
            view.run_command('save')
            window.run_command('close')

        elif string == 'q!':
            if view.is_dirty():
                view.run_command('revert')

            window.run_command('close')

        elif string == 'q':
            if not view.is_dirty():
                window.run_command('close')

        elif string == 'x':
            if view.is_dirty():
                view.run_command('save')

            window.run_command('close')

        elif string == 'n':
            window.run_command('next_view')

        elif string == 'N':
            window.run_command('prev_view')

        if line != None:
            point = view.text_point(line, 0)

            sel.clear()
            line = view.line(point)

            cur = sublime.Region(line.a, line.a)
            sel.add(cur)

            view.show(sel)
Example #16
0
def convert_string_to_integer(string):
    return int(string) if string.isdigit() else -1
def Format(string, length):
    spaces = ' ' * (length - len(string))
    if string.isdigit():
        return spaces + string
    else:
        return string + spaces
Example #18
0
    def key_colon(self, edit, string):
        view = self.view
        window = view.window()
        sel = view.sel()
        line = None

        start = string[0]
        remains = string[1:]
        if start in ("+", "-") and remains.isdigit():
            view.run_command("single_selection")
            line = view.rowcol(sel[0].a)[0]
            shift = int(remains)

            if start == "+":
                line += shift
            else:
                line -= shift

        elif string == "$":
            line = view.visible_region().b

        elif string.isdigit():
            line = max(int(string) - 1, 0)

        elif string == "w":
            self.save()

        elif string == "wq":
            view.run_command("save")
            window.run_command("close")

        elif string == "q!":
            if view.is_dirty():
                view.run_command("revert")

            window.run_command("close")

        elif string == "q":
            if not view.is_dirty():
                window.run_command("close")

        elif string == "x":
            if view.is_dirty():
                view.run_command("save")

            window.run_command("close")

        elif string == "n":
            window.run_command("next_view")

        elif string == "N":
            window.run_command("prev_view")

        if line != None:
            point = view.text_point(line, 0)

            sel.clear()
            line = view.line(point)

            cur = sublime.Region(line.a, line.a)
            sel.add(cur)

            view.show(sel)
Example #19
0
                                        'type'] != 'hidden':
                                    block_id = makeBlock(
                                        siteID, element['value'], element.name,
                                        url)
                                    if block_id is not False:
                                        makePageBlock(getPageID(url, siteID),
                                                      block_id)
                            else:
                                if element.name == 'meta':
                                    continue

                                for str_ in element.findAll(text=True,
                                                            recursive=False):
                                    pprint(str_)
                                    string = re.sub(' +', ' ', str_)
                                    if string.isdigit(
                                    ) != True and string:  #Цифры нам нинужныыыы!
                                        block_id = makeBlock(
                                            siteID, string, element.name, url)
                                        if block_id is not False:
                                            makePageBlock(
                                                getPageID(url, siteID),
                                                block_id)

                            # Сначала чекаем на файлы и картинки
                            if element.name == 'img' or element.name == 'IMG' or element.name == 'a':
                                parseDocInSite(url, element)

                    count += 1
                    del html

                except Exception as exc:
# isdigit()
'''
 |  isdigit(...)
 |      S.isdigit() -> bool
 |      
 |      Return True if all characters in S are digits
 |      and there is at least one character in S, False otherwise.
'''
	# Digit: 0...9
import string
print(string.digits)
string = "123"
print("Is the string '%s' is digit? %s" % (string, string.isdigit()))
string = "12.3"
print("Is the string '%s' is digit? %s" % (string, string.isdigit()))
string = "12 3"
print("Is the string '%s' is digit? %s" % (string, string.isdigit()))
string = "12EF"
print("Is the string '%s' is digit? %s" % (string, string.isdigit()))
string = ""
print("Is the string '%s' is digit? %s" % (string, string.isdigit()))