[go: up one dir, main page]

0% found this document useful (0 votes)
7 views3 pages

List Shell

Uploaded by

devishi.grover13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

List Shell

Uploaded by

devishi.grover13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.

1916 32 bit (Intel)]


on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> l1=[900,920,200,9810]
>>> l1.append(820)
>>> l1
[900, 920, 200, 9810, 820]
>>> l2=['hello','lion']
>>> l1.append(l2)
>>> l1
[900, 920, 200, 9810, 820, ['hello', 'lion']]
>>> l2.append(l1)
>>> l2
['hello', 'lion', [900, 920, 200, 9810, 820, [...]]]
>>> l1
[900, 920, 200, 9810, 820, ['hello', 'lion', [...]]]
>>>
=============================== RESTART: Shell ===============================
>>> l1=[23,4,5,7,8]
>>> l1.append(900)
>>> l1
[23, 4, 5, 7, 8, 900]
>>> l2=[90,89,78]
>>> l1.append(l2)
>>> l1
[23, 4, 5, 7, 8, 900, [90, 89, 78]]
>>> l2
[90, 89, 78]
>>> l2.append(l1)
>>> l1
[23, 4, 5, 7, 8, 900, [90, 89, 78, [...]]]
>>> l2
[90, 89, 78, [23, 4, 5, 7, 8, 900, [...]]]
>>>
=============================== RESTART: Shell ===============================
>>> l1=[900,800,280]
>>> l2=l1=[23,4,5,7,8]
>>>
=============================== RESTART: Shell ===============================
>>> l1=[900,800,280]
>>> l2=[23,4,5,7,8]
>>> l1.extend(l2)
>>> l1
[900, 800, 280, 23, 4, 5, 7, 8]
>>> #APPEND ADDS IN FORM OF A LIST
>>> #EXTEND ADDS IN FORM OF ELEMENTS IN THAT SAME LIST
>>> len(l1)
8
>>> """l1.pop(Index no of the element to be removed)"""
'l1.pop(Index no of the element to be removed)'
>>> l1.pop()
8
>>> # 8:-ELEMENT DELETED FROM l1
>>> l1
[900, 800, 280, 23, 4, 5, 7]
>>> #since no arguement in pop() therefore removes last element
>>> l1.pop(900)
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
l1.pop(900)
IndexError: pop index out of range
>>> #--------DOES NOT ACCEPT ELEMENTS.....ONLY ACCEPTS INDEX------------
>>> l1.pop(-3)
4
>>> l1
[900, 800, 280, 23, 5, 7]
>>> #TO REMOVE PARTICULAR ELEMENT remove(element to be removed) is used
>>> l1.remove(900)
>>> l1
[800, 280, 23, 5, 7]
>>> #REMOVE DOES NOT DISPLAY[RETURN] THE ELEMENT WHICH IS DELETED
>>> [800, 280, 23, 5, 7]
[800, 280, 23, 5, 7]
>>>
>>>
>>> #INSERTING ELEMENTS INTO AN EXISTING LIST
>>> #l1.insert(index no at which elements is to be inserted,Element)
>>> l1.insert(3,568)
>>> l1
[800, 280, 23, 568, 5, 7]
>>>
>>> #COUNTING NUMBER OF ELEMENTS
>>> l1.insert(2,23)
>>> l1
[800, 280, 23, 23, 568, 5, 7]
>>> l1.count(23)
2
>>> l1.count("elsa")
0
>>> #SORTING
>>> l1.sort()
>>> l1
[5, 7, 23, 23, 280, 568, 800]
>>> #ARRANGED IN ASCENDING ORDER
>>> l1.sort(reverse=True)
>>> l1
[800, 568, 280, 23, 23, 7, 5]
>>> #ARRANGED IN DESCENDING ORDER
>>>
>>> #CHECKING INDEX NUMBER
>>> l1.index(23)
3
>>> l
Traceback (most recent call last):
File "<pyshell#64>", line 1, in <module>
l
NameError: name 'l' is not defined
>>> #REVERSING OF LIST
>>> l4=[23,45,6,7,8,9]
>>> l4.reverse()
>>> l4
[9, 8, 7, 6, 45, 23]
>>> l3.clear()
Traceback (most recent call last):
File "<pyshell#69>", line 1, in <module>
l3.clear()
NameError: name 'l3' is not defined
>>> l4.clear()
>>> l4
[]
>>> # L4 is cleared......Implies exists as and empty listl4=[23,45,6,7,8,9]
>>> # L4 is cleared......Implies exists as and empty list
>>> l4=[23,45,6,7,8,9]
>>> min(l4)
6
>>> max(l4)
45
>>> sum(l4)
98
>>> #SUM OF ALL ELEMENTS OF LIST

You might also like