INT104-lab3

 

 1 def remove_odd_elements(mylist:list):
 2     return [element for element in mylist if(element//2*2==element)]
 3 
 4 # a=[12,15,3,10]
 5 # print(remove_odd_elements(a))
 6 
 7 
 8 def count_occurrences_element(lst:list,x):
 9     lst=[a for a in lst if(a==x)]
10     return len(lst)
11 
12 '''
13 lst=[15,6,7,10,12,20,10,28,10]
14 x=10
15 lst=[8,6,8,10,8,20,10,8,8]
16 x=8
17 print(count_occurrences_element(lst,x))
18 '''
19 
20 def remove_duplicates_characters(s:str):
21     myset=set()
22     for c in s:
23         if not c in myset:
24             print(c,end='')
25         myset.add(c)
26     print()
27 
28 
29 # s="abababababababaababababbc"
30 # remove_duplicates_characters(s)
31 
32 
33 def count_pattern_from_text(text:str):
34     words=text.split(' ')
35     dict={word: words.count(word) for word in words}
36     print(dict)
37 
38 
39 # text="python hello this is my world hello world world"
40 # count_pattern_from_text(text)
41 
42 
43 import numpy as np
44 
45 
46 def matrix_multiple(A,B):
47     C=np.dot(A,B)
48     return C
49     '''
50     print(type(C))
51     print(C)
52     print(type(C.tolist()))
53     print(C.tolist())
54     '''
55 
56 
57 # A=[[12,7,3],[4,5,6],[7,8,9]]
58 # B=[[5,8,1,2],[6,7,3,0],[4,5,9,1]]
59 # matrix_multiple(A,B)

 

posted @ 2021-03-15 18:05  墨鳌  阅读(65)  评论(0编辑  收藏  举报