Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assignment 1 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Python-SMP/Week-20/harsha/assignment1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
1.First output:
['1','S','T','E']
['1','S','T','E']
Reason is that list2=list1 creates same object so any change in list2 will be reflected in list1. list1=list1+[] will create a new object,list1. So after that change in list2 will not be reflected in list1.
Second output:
['1','S','T','E']
['1',2,'T','E']
For the first one reason is same that list2=list1.list1+=[] will not create anynew object. So change in list2 will be reflected in list1.

2.#part1
list=[42,61,58,2,82,67,102,78]
for i in range(len(list)) :
for j in range(len(list)-1-i) :
if list[j]>list[j+1] :
b=list[j]
list[j]=list[j+1]
list[j+1]=b
print(list)

#part2
list=[42,61,58,2,82,67,102,78]
b=67
for i in range(len(a)) :
if list[i]==b :
break
print(e ," found at index ",i)


3.Output:
False
True
Reason is that l1 and l2 are different objects but both str1 and str2 are the same object.

4.list=[a for a in list if a*a*a%3==1]