Example #1
0
def LetterCountI(str): 
    def ischar(char):
        if char.upper()>="A" and char.upper()<="Z":
            return True
        else:
            return False
    maxrepeatedtimes=0 
    maxrepeatedword=""
    i=0
    while i<len(str):
        count={}
        currentword=""
        while i<len(str) and not(str[i]==" "):
            currentword+=str[i]
            count.setdefault(str[i],0)    # if we don't have char, it will be added and 0 instances
            count[str[i]]+=1  
            i+=1
        
        maxtmp=max(count, key=count.get)
        #print ("for the word /",currentword,"/ max repeated letter numer is: ", count[maxtmp])
        if count[maxtmp]>maxrepeatedtimes:
             maxrepeatedtimes=count[maxtmp]
             maxrepeatedword=currentword
        i+=1
    if maxrepeatedtimes==0:
        return -1
    else:
        return   maxrepeatedword
Example #2
0
def LetterCountI(str):
    def ischar(char):
        if char.upper() >= "A" and char.upper() <= "Z":
            return True
        else:
            return False

    maxrepeatedtimes = 0
    maxrepeatedword = ""
    i = 0
    while i < len(str):
        count = {}
        currentword = ""
        while i < len(str) and not (str[i] == " "):
            currentword += str[i]
            count.setdefault(
                str[i],
                0)  # if we don't have char, it will be added and 0 instances
            count[str[i]] += 1
            i += 1

        maxtmp = max(count, key=count.get)
        #print ("for the word /",currentword,"/ max repeated letter numer is: ", count[maxtmp])
        if count[maxtmp] > maxrepeatedtimes:
            maxrepeatedtimes = count[maxtmp]
            maxrepeatedword = currentword
        i += 1
    if maxrepeatedtimes == 0:
        return -1
    else:
        return maxrepeatedword
Example #3
0
            newstr+="-"+str[i]
            i+=1
        if i<len(str):
            if odd(str[i]) and odd(str[i-1]) and i>0:
                newstr+="-"
            newstr+=str[i]
        i+=1
    return(newstr)
print (DashInsert("777773055544448899281274727777"))


#count number of instances of each character in a string
sentence="This is a nice long sentence with many words"
count={}
for char in sentence:
    count.setdefault(char,0)    # if we don't have char, it will be added and 0 instances
    count[char]+=1                      # the previous command set the instance to 0 if this is the first time. now, number of instances is raised by 1; 
                                                        # so either it will be 1, or increased by 1.
print (count)




#variables
x3=7
def fun01():
    print (x3)
    #global x3 # by default, Python will scope variable inside block. adding "global" tells to use the global variable x3
    #x3=8 # it will take the global x3 and assign to it 8
    #x3=x3+5 #now global x3 equels 13
    return x3 #returns 13
Example #4
0
            i += 1
        if i < len(str):
            if odd(str[i]) and odd(str[i - 1]) and i > 0:
                newstr += "-"
            newstr += str[i]
        i += 1
    return (newstr)


print(DashInsert("777773055544448899281274727777"))

#count number of instances of each character in a string
sentence = "This is a nice long sentence with many words"
count = {}
for char in sentence:
    count.setdefault(
        char, 0)  # if we don't have char, it will be added and 0 instances
    count[
        char] += 1  # the previous command set the instance to 0 if this is the first time. now, number of instances is raised by 1;
    # so either it will be 1, or increased by 1.
print(count)

#variables
x3 = 7


def fun01():
    print(x3)
    #global x3 # by default, Python will scope variable inside block. adding "global" tells to use the global variable x3
    #x3=8 # it will take the global x3 and assign to it 8
    #x3=x3+5 #now global x3 equels 13
    return x3  #returns 13