Python Questions
5.33K subscribers
1 photo
7 links
Tasks for Beginners, Interview Questions, Regular expressions, simple coding problems, Quiz etc.

Useful Resources — »»» @python_resources_iGnani
Projects for Practice — »»» @python_projects_repository
Discussion Forum — »»» @python_programmers_club
Download Telegram
*

myList = [1, 2, 3, 4, 2, 2, 3, 1, 4, 4, 4,5,5,6,7,6,5]

A) Write a program to get the value that appears more number of times
B) When there is a tie, then get the number which is the smallest of them

#python #practiceCode #samples #interviewQuestions #numbers #list
*

name = 'ppy!'
Write code to insert the letter 'a' in-between each letter to form the word 'papaya!'

#python #practiceCode #samples #interviewQuestions #strings #list
#interviewQuestions : 0008

Q: List.copy() does a shallow copy of the list, but when we check their id's they point to different address? Why?

A shallow copy means constructing a new collection object and then populating it with references to the child objects found in the original.

Hence, when you check their id's they both point to different address.

check out this code
L1 = 1, 2, 3, 4

# Using copy() to create a shallow copy
L2 = L1.copy()

print(id(L1), id(L2))
>>> 2763664559240 2763665433480
In the above result, address are different, they both point to different locations.


But, the elements will be pointing to the same objects in both the
lists.
Check this code:

print(id(L10), id(L20))
>>> 140703554137856 140703554137856

See the result, the elements point to the same address in memory.

#list #collection #shallowCopy