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 #10

Open
wants to merge 4 commits 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
17 changes: 17 additions & 0 deletions Assignment 1/Karn Tiwari/Question 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
List1=['I','S','T','E']
List2=List1
List2[0]=’1’
print(List1) #['1', 'S', 'T', 'E'] id of list1 and list2 are same object so any change in list2 is reflected in list1
List1=List1+[]
List2[1]=2
print(List1) #['1', 'S', 'T', 'E'] id of list1 and list2 are now differen object as list1 is concatenated with Null list

#Yes the output is different

List1=['I','S','T','E']
List2=List1
List2[0]=’1’
print(List1) #['1', 'S', 'T', 'E'] id of list1 and list2 are same object so any change in list2 is reflected in list1
List1+=[]
List2[1]=2
print(List1) #['1', '2', 'T', 'E'] id of list1 and list2 are same object
31 changes: 31 additions & 0 deletions Assignment 1/Karn Tiwari/Question 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#Sorting of elements
arr=[10,9,8,7,6,5,4,3,2,1]
print(arr)
d=len(arr)
for i in range(d):
for j in range(i+1,d):
if arr[i]>=arr[j]:
arr[i],arr[j]=arr[j],arr[i]
print(arr)

#Binary search Algorithm
key=5
ma=d
mi=0
y=0

while ma>mi:
mid=int((ma+mi)//2)
if key==arr[mid]:
y=1
p=mid+1
break
elif key>arr[mid]:
mi=mid
else:
ma=mid

if y==1:
print("key element found @ ",p)
else:
print("key element not found")
8 changes: 8 additions & 0 deletions Assignment 1/Karn Tiwari/Question 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
l1=[1,2,3]
l2=[1,2,3]
print(id(l1)==id(l2)) # False for two list of same element id is different,different object

str1='good'
str2='good'
print(id(str1)==id(str2)) # True for same numbers and string id is different,same object

2 changes: 2 additions & 0 deletions Assignment 1/Karn Tiwari/Question 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a=[1,2,3,4,5,6,7,8,9,10]
a=[i for i in a if ((i**3)%3)==1] # [1,4,7,10] one line code