Untitled

 avatar
unknown
python
a month ago
634 B
7
Indexable
def func(string,ch,num):
    counter = num
    returned_str = ""
    for i in string:
        if ord(i) == ord(ch) and counter != 0:
            if 32 < ord(i) < 47:
                returned_str += chr(ord(i))
            else:
                returned_str += chr(ord(i)- 32)
                counter -= 1
        else:
            returned_str += chr(ord(i))
    return returned_str

def func1(lst,ch,num):
    for item in range(len(lst)):
        lst[item] = func(lst[item],ch,num)
    return lst

def main():
    lst = ['abcc','abc','cagfc']
    print(func1(lst, 'c', 4))
    #print(func("abc$","$",1))
main()
Editor is loading...
Leave a Comment