# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
s = "hello"
t = list(s)
print(t)
for i in t:
    print(i,t.count(i))
   
    

    

# +
p = "hello"


for i in range(len(p)):
    if p[i] == 
   
# -

# # dictionaries

# +
score = {}
score["test1"] = {}
score["test2"] = {}
score["test1"]["kholi"] = 76
score["test2"]["kholi"] = 88
score["test2"]["dhoni"] = 100
 

# -

score


score.keys()

# +
l = {}
for i in "abcdefghijk":
    l[i] = i

l["a"]    

# -

l["b"]

l.keys()

l.values()

total = 0
for i in l.values():
    total = total + i
print(total)    


geeks = {}
geeks["a"] = "geeks"
geeks["b"] = "geeks"




for i in geeks:
    print(i)

geeks

geeks["a"]

geeks.keys()

score = {}
score["test1"] = {}
score["test2"] = {}
score["test1"]["kholi"] = 76
score["test2"]["kholi"] = 88
score["test2"]["dhoni"] = 100
score = score["test1"]["kholi"] + score["test2"]["kholi"] 
score


total


score["test1"].keys()

# +
matches = {}
matches["match1"] = {}
matches["match2"] = {}
matches["match1"]["ronaldo"] = 30
matches["match2"]["messi"] = 20
matches["match2"]["ronaldo"] = 30
matches["match1"]["messi"] = 5





# +
totalscore = {}
for i in ["ronaldo","messi"]:
    totalscore[i] = 0
    for j in matches.keys():
        if i in matches[j].keys():
            totalscore[i] = totalscore[i] + matches[j][i] #matches["match1"]["ronaldo"]
matches["match1"]["ronaldo"]
print(totalscore)            
        
        
    
    
    

# +
totalscore = {}
for i in ["ronaldo","messi"]:
    totalscore[i] = 0
    for j in matches.keys():
        if i in matches[j].keys():
            print(i)
            


# +

s = [20,30,40,50,60]
sum = 0
for i in s:
    sum = sum + i

print("ronaldo" +" - ",sum)  
print("messi" +" - ",sum)
# -

# # code to find the number of freq of stings

# +
# basic for the programme that we are about to execuite
d = {}
d["del"] = {}
d["del"] = 69
d["del"] = d["del"] + 1
 


# -

d

# code to find the number of occurance of given charecter in the string


str = input("enter the string:")
p = {}
for i in str:
    if i in p:
        p[i] = p[i] + 1
    else:
        p[i] = 1
print(p)        

# +
from collections import Counter 
    
# initializing string  
in_str = "GeeksforGeeks"
    
# using collections.Counter() to get  
# count of each element in string  
oup = Counter(in_str) 
    
# printing result  
print ("Occurrence of all characters in GeeksforGeeks is :\n "+ str(oup))

# +
l= "neeraj"
s = list(l)
print(s)
for i in s:
    if i > count(i):
        
   


# -

# programme to find matching words in  the string
t  = input("enter the string:")
c = input("enter the substring:")
matcher = []
for i in t:
    if i in c:
        matcher.append(i)
print(matcher)        

# +
#programme to find the number of occurance of words in first string with the second string
c  = input("enter the first string:")
d  = input("enter the second string:")
list = []
dic = {}
for i in c:
    if i in d:
        list.append(i)
        
for j in list:
    if j in dic:
        dic[j] = dic[j] + 1
    else:
        dic[j] = 1
print(dic)        
        
    
# -

def div(a,b):
    print(a/b)
    


div(10,5)


# # decorator

# +
def div(a,b):
    print(a/b)

def mod_div(fun):
    def inner(a,b):
        if a < b:
            a,b = b,a
        fun(a,b)
    return(inner)

div = mod_div(div)

div(2,4)

    
    
# -

def count_char(text):
  for i in range(len(text)):
    if len(text) == 0:
      break;
    ch = text[0]
    if ch == ' ' or ch == '\t':
      continue
    print(ch + " - ", text.count(ch))
    text = text.replace(ch, '').strip()


count_char("hello")


# +
def add(x,y):
    p = x + y
    b = print(p)
    return(b)

x = int(input("enter the first number: "))
y = int(input("enter the second number: "))
num = add(x,y)
print(num)

# -

print("assindhur")


# +

def cube(x):
    return(x*x*x)


# -

cube(3)

l = [1,2,3,4,5,6]
l.sort()
print(l)


# # binary search
#     

# +
def bsearch(seq,v,l,r):
    if l-r == 0:
        return(False)
    mid = l+r//2
    
    if v == seq[mid]:
        return(True)
    elif v < seq[mid]:
        return(bsearch(seq,v,l,mid))
    else:
        return(bsearch(seq,v,mid+1,r))
        
        
        
# -

bsearch([1,2,3,4,5,6,7,8,9],3,1,7)


def findpos(l,v):

    for i in range(len(l)):
        if l[i] == v:
            print("the element is found in the list")
            break

            
    
    else:
        print("the element is not found in the list")


findpos([1,2,3,4,5,6,7],10)

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

# +
l = [74,32,89,99,100,111,55,21,64,34]


for i in l:
    if i < l[2]:
        minpos = i # here for different excecution the min pos is same hence for how many times the loop excecuted the minpos will get printed that many timess
    print(minpos) 
       
        
       
        
  
        
    
   
    
   
                
        

        


   
    
 

# +
l = [74,32,89,99,100,111,55,21,64,34,38]


for i in l:
    if i < l[2]:
        minpos = i 
        print(minpos)        
        
        
# -



l = [74,32,89,55,21,64]
len(l)


# +
def selectionsort(v):
    red = 0
    
    for h in range(0,len(v)):
        if v[h] < v[red]: 
            red = h
        print(red)
       
        
    
        
        
    
    
    
        
       
                
                
        
        
        
    
        
    
            
# -

selectionsort([74,32,89,55,21,64])

for i in range(0,6):
    print(i)


# +
def selectionsorto(m):
    for start in range(len(m)):
        minpos=start
        
        for i in range(start,len(m)):
            if m[i]<m[minpos]:
                minpos = i
                
                
        (m[start],m[minpos]) = (m[minpos],m[start]) 



                

# +
m = [55,1,8,100,10000,56,34]
selectionsorto(m)



StarcoderdataJupyterScriptsDedupFiltered