CBSE COMPUTER SCIENCE
Відкрити в Telegram
QUESTION BANK, REFERENCE BOOK, LAB MANUAL , WORKSHEET ETC., PYTHON TEXT BOOK AND REFERENCE BOOKS, 01. ASK QUESTIONS AT https://t.me/joinchat/FJ1noGs-64I0OWI1
Показати більше549
Підписники
Немає даних24 години
Немає даних7 днів
Немає даних30 день
Архів дописів
['h', 'g', 'f', 'e', 'd', 'c', 'b']
[]
['h', 'g', 'f', 'e', 'd', 'c', 'b']
['h', 'g', 'f', 'e', 'd']
['g', 'f', 'e', 'd']
['g', 'f', 'e', 'd', 'c']
['h', 'g', 'f', 'e', 'd', 'c']
>>>
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
print(l[-2:-9:-1])
print(l[-9:-2:-1])
print(l[7:0:-1])
print(l[7:2:-1])
print(l[-3:2:-1])
print(l[-3:-8:-1])
print(l[7:-8:-1])
b="Practice in Python"
a=list(b)
print(a)
print(len(a))
print(a[1:4])
print(a[1:7])
OUTPUT
['P', 'r', 'a', 'c', 't', 'i', 'c', 'e', ' ', 'i', 'n', ' ', 'P', 'y', 't', 'h', 'o', 'n']
18
['r', 'a', 'c']
['r', 'a', 'c', 't', 'i', 'c']
>>>
>>> a="Python"
>>> b=list(a)
>>> b*2
['P', 'y', 't', 'h', 'o', 'n', 'P', 'y', 't', 'h', 'o', 'n']
>>> b+b
['P', 'y', 't', 'h', 'o', 'n', 'P', 'y', 't', 'h', 'o', 'n']
>>> a+a
'PythonPython'
>>>
k="Subscribe to my blog"
L=list(k)
print(L[-1:-7:-3])
print(L[:15:-1])
print(L[1:len(k):5])
print(L[2:-15])
OUTPUT
['g', 'b']
['g', 'o', 'l', 'b']
['u', 'i', 'o', 'b']
['b', 's', 'c']
>>>
You can watch *Working with Functions XII CS* (Dated 05-04-21) by click on the following link.
https://youtu.be/v9Btp3iTI1I
# Python program to count the frequency of
# elements in a list using a dictionary
def CountFrequency(my_list):
# Creating an empty dictionary
freq = {}
for item in my_list:
if (item in freq):
freq[item] += 1
else:
freq[item] = 1
for key, value in freq.items():
print ("% d : % d"%(key, value))
# Driver function
if name == "main":
my_list =[1, 1, 1, 5, 5, 3, 1, 3, 3, 1, 4, 4, 4, 2, 2, 2, 2]
CountFrequency(my_list)
