-
Notifications
You must be signed in to change notification settings - Fork 0
/
datatyp.py
428 lines (255 loc) · 6.64 KB
/
datatyp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# tuple accessing
# t1=(1,2,3,4,5)
# li=list(t1)
# li.append(26)
# tu=tuple(li)
# print(type(li))
# print(t1)
# print(li)
# print(tu)
# print(t1+t2)
# result= [x for x in t1 if x%2==0]
# print(result)
# Create a list of your favorite fruits and print the second item.
# Given a list of numbers, find the sum and average of all the elements.
# Remove duplicates from a list without changing the order of elements.
# Reverse a list in-place without using any built-in functions.
# Given a list of strings, create a new list containing only the strings with more than 5 characters.
# Check if a list is empty.
# ........list accecing.........
# input_list=[20,22,33,44,33]
#sum and avarage........
# sum=sum(input_list)
# print(sum)
# avrg= sum/len(input_list)
# print(avrg)
#remove dublucations in list.......
# def remove_dublications(value):
# seen=set()
# result=[]
# for items in value:
# if items not in seen:
# seen.add(items)
# result.append(items)
# return print(result)
# remove_dublications(input_list)
# reverse_print........
# print(input_list[::-1])
# new list morthan 5 characters.........
# string_list=['shammas','uvais','thouseef']
# result2=[]
# result=[x for x in string_list if len(x) > 5] #with list comprehention
# print(result)
# for i in string_list: #with for loop
# if len(i) > 5:
# result2.append(i)
# print(result2)
#using python filter function.........
# result1=filter(lambda x: x %2==0, li) #even
# result2=[x for x in li if x%2==1] #odd
# print(list(result1))
# print(result2)
# if li:
# print('list is not empty')
# else:
# print('list is empty')
# li=[1,3,4,5,6,67,2]
# fixed=10
# print([fixed + x for x in li])
# nested=[[1,2,3,4],[5,6,7,8]]
# print([sum(row) for row in nested])
# print([sum(col) for col in zip(*nested)])
# print(nested[1][2])
# for i in nested:
# for j in i:
# sum=[]
# if j is not None:
# sum.append(j)
# print(sum)
# new_list=[x**2 for x in li] #new list with squred value from existing list
# new=list(map(lambda x: x**2,li)) # with lampda function
# print(new)
# print(new_list)
# result=li[::-1] #reverse
# print(result)
# print(li[1::2]) #print all second element
# li[1],li[5]=li[5],li[1] #swaping
# print(li)
# list1=[1,2,3,4,5,6,7]
# position_to_remove = int(input("Enter the position to remove: "))
# if 0 <= position_to_remove < len(list1):
# list1 = list1[:position_to_remove] + list1[position_to_remove + 1:]
# print("Updated list:", list1)
# else:
# print("Invalid position. The list was not modified.")
# print(li.index(22))
# print(li[1])
# li.remove(20)
# print(li)
# result=[]
# for x in li:
# result.append(x+1)
# print(result)
# insert=li.insert(2,8)
# print(li)
# li.remove(8)
# li.append(26)
# l2=[x for x in li if x%2==0]
# print(l2)
#12-10-23............................
# x=(1,2,3)
# y=x
# x=(1,2,3,4,5)
# print(x,y)
# def sorting_number(number):
# number.sort()
# return number
# number=[78,545,67,343,2,355,23,55]
# print(number)
# result=sorting_number(number)
# print(number)
# x=(1,2,3,4,5,6)
# print(x.index(1))
# list_comprehention.......................
# x=[[j for j in range(5)] for i in range(5) if i%2==0]
# print(x)
# function_argument_accessing....................
# def complicated_functio(x,z=10,y=None):
# print(x,y,z)
# pass
# complicated_functio(2,6)
#>>>>>>>>>
# def complicated_function(x,y, *args, **kwargs):
# print(x,y,args,kwargs)
# pass
# complicated_function(1,2,34,4,556,6,a=True,b='shammas',c=False)
#>>>>>>>>>
# def compi_next(a,b,c=True,d=False):
# print(a,b,c,d)
# pass
# compi_next(1,2,'hello','cool')
#if __name__=="__main__".............................imported in others.py
# def add(a,b):
# result=a+b
# return print(result)
# if __name__=="__main__":
# add(10,29)
# print('iam datatyp file')
# def func(x):
# result = x**x
# return print(result)
# func(3)
# find fibnochi sequence
# def fibnochi(n):
# sequnce=[0,1]
# while len(sequnce) < n:
# result=sequnce[-1]+sequnce[-2]
# sequnce.append(result)
# return print(sequnce[:n])
# input=int(input('enter a number'))
# fibnochi(input)
# def fibnochi(n):
# sequence=[0,1]
# while len(sequence) < n :
# result=sequence[-1] + sequence[-2]
# sequence.append(result)
# return print(sequence)
# fibnochi(5)
# def reverse(a):
# # list1=[]
# x=''
# for i in a:
# x = i + x
# return print(x)
# reverse("abcde")
# a=["shammas","malayalam"]
# new=[x for x in a if x == x[::-1]]
# print(new)
#count of string............
# def count_of_string(n):
# dic={}
# for i in n:
# if i in dic:
# dic[i] += 1
# else:
# dic[i] = 1
# for i , count in dic.items():
# print(i,':',count)
# count_of_string('muhammed shammas')
# def palindrom(n):
# st=''
# for i in n:
# st = i + st
# if n == st:
# print('palindrom')
# else:
# print("not palindrom")
# palindrom('malayalam')
# def remove_even_numbers(*args):
# li=[]
# for i in args:
# if i%2==1:
# li.append(i)
# print(li)
# remove_even_numbers(1,2,3)
# remove dublications
# l1=[1,2,3,4,5,5,4,3,5]
# l2=[1,2,3,4,5,5,6,9,8,8,7,6]
# new=[]
# same=[]
# for i in l2:
# if i not in new:
# new.append(i)
# else:
# same.append(i)
# print(new,same)
# lis=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
# for i in range(len(lis)):
# if lis[i] % 5 != 0:
# lis[i]=5
# else:
# lis[i]=i+1
# print(lis)
# strs = ["dog","racecar","car"]
# print(sorted(strs))
# n=5
# while n is not None:
# i=[]
# i.append(n)
# print(i)
# def coun_of_string(n):
# dic={}
# for i in n:
# if i in dic:
# dic[i] += 1
# else:
# dic[i] = 1
# for i,count in dic.items():
# print(i,':',count)
# coun_of_string('shammas')
# class middleware:
# def __init__(self,get_response):
# self.get_response = get_response
# def __call__(self,request):
# response = self.get_response(request)
# return response
# def decor(orginal):
# def inner(j,i):
# print(j*i)
# return orginal(j,i)
# return inner
# @decor
# def sample(x,y):
# return x+y
# print(sample(5,5))
# print("ok bi")
# result=decor(sample)
# print(result(5,5))
#...................
# l1=[1,2,3,4,5]
# l2=['a','b','c','d','e']
# my_dic=dict(zip(l2,l1))
# print(my_dic)
set1={1,3,5,7,2,4}
set1.add()
print(set1)