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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions Week-1/Shubham_Dubey/que1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
output :-
['1', 'S', 'T', 'E']
['1', 'S', 'T', 'E']

output with list1+=[]

['1', 'S', 'T', 'E']
['1', 2, 'T', 'E']

Assignment with list2 = list1 does not make a copy. Instead, assignment makes the two variables point to the one list in memory.
so if we change list2 it will reflect in list1 because they are same

list1=list1+[] and list1+=[] are supposed to work same but in case of list it's not i don't know why and i am unable to find it on web also, please explain..
8 changes: 8 additions & 0 deletions Week-1/Shubham_Dubey/que2.1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> list=[3,1,5,2,4]
for i in range(5):
for j in range(i,4):
if list[j]>list[j+1]:
list[j],list[j+1]=list[j+1],list[j]
print(list)
23 changes: 23 additions & 0 deletions Week-1/Shubham_Dubey/que2.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def binary(a,low,high,key):
while low<=high:
mid=int((high+low)/2)
if a[mid]==key:
return 1
break
elif a[mid]<key:
low=mid+1
elif a[mid]>key:
high=mid-1
return 0;





a=[1,2,3,4,5,6,7,8,9,10]

no=int(input("Enter the no you want to search"))
if binary(a,0,9,no):
print("Element found")
else:
print("Element Not found")
2 changes: 2 additions & 0 deletions Week-1/Shubham_Dubey/que3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
False
True
5 changes: 5 additions & 0 deletions Week-1/Shubham_Dubey/que4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> list1=[1,2,3,4,5,6,7,8,9,10,11,12,13]
list=[i for i in list1 if i%3==1 ]
print(list)