List Examples

 



List Searching 


pos = -1

def search1(list1,n):

        i = 0

        while i<len(list1):

                if list1[i] == n:

                        globals()['pos']=i

                        return True

                i =i+1

        return False

l = [1,2,3,4,50]

print(l)

n = int(input('enter the number to find the list: '))

if search1(l,n):

        print('found',pos)

else:

        print('not found',pos)


About log :
    User will enter the value to find in the list.
    Create the search function
    While loop 
     Finding the index is using When globals() is called from a function or method, it returns the dictionary representing the global namespace of the module where the function or method is defined, not from where it is called.



Comments

Popular posts from this blog

Function in Python Examples