From b6234e28efcf7090e082fb11a81e9efce26458ab Mon Sep 17 00:00:00 2001 From: 27shruti <44189552+27shruti@users.noreply.github.com> Date: Tue, 14 May 2019 14:34:07 +0530 Subject: [PATCH] Add files via upload --- assignment 1 iste python.txt | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 assignment 1 iste python.txt diff --git a/assignment 1 iste python.txt b/assignment 1 iste python.txt new file mode 100644 index 0000000..96a42c1 --- /dev/null +++ b/assignment 1 iste python.txt @@ -0,0 +1,38 @@ +A1) Both the results are same, as list1+=[] is equivalent to list1 = list1 + []. + Result of print(lis1) is [‘1’,’S’,’T’,’E] + But print(list2) is [‘1’,’2’,’T’,’E’] +In the end the identity of the list1 got changed due to addition of []. Hence changing the value of list2 doesn’t change the value of list1 anymore as both of them point to different objects now due to change in the id of both the lists. + +A2) for j in range(len(a)): +... swapped= False +... i=0 +... while ia[i+1]: +... a[i],a[i+1] = a[i+1],a[i] +... swapped= True +... i=i+1 +... if swapped== False: +... break + +list=9 +list1=[7,8,9,10] +>>> for i in range(len(list1)): +... if list==list1[i]: +... print('element found at posn',i) +... else : +... i+=1 +... +element found at posn 2 + +A3) False, True +Result of first print is False because == is a relational operator and it compares the ID of the 2 lists. It wont be true until both the lists point to the same object. + Result of second print is True because strings are not evaluated like arrays in python.] + +A4) + i=0 +>>> list1=[7,8,9,10] +>>> for i in range(len(list1)): +... if (list1[i]*list1[i]*list1[i])%3!=1: +... list1.remove(i) +... else: +... break