Posts

Showing posts from December, 2024

**Prepare Well**

Question 1: How do you create a list and add elements dynamically?   #Create a list and add numbers dynamically a=[ 1 , 2 , 3 ] def add_dyn_ele ( a , b ): a.append(b) print (a) add_dyn_ele(a, 10 ) Question 2: How do you merge two dictionaries? If you give same key it will overwrite the values and wont update. #Merge 2 dictionaries a={ 'name' : 'Suchitra' , 'age' : 10 } b={ 'name1' : 'Suni' , 'age1' : 20 } def mergedict ( a , b ): a.update(b) return a print (mergedict(a,b)) Suchitra ran 12 lines of Python 3 (finished in 1.01s): {'name': 'Suchitra', 'age': 10, 'name1': 'Suni', 'age1': 20} >>> #Another way is : a={ 'name' : 'suchi' , 'age' : 10 , 'city' : 'bangalore' } b={ 'name1' : 'baby' } c={ 'name2' : 'baby' , 'mom2' : 'suchi' } print ( "Other way to merge is : " ,...