-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathw3r ex on array.py
More file actions
136 lines (85 loc) · 2.94 KB
/
w3r ex on array.py
File metadata and controls
136 lines (85 loc) · 2.94 KB
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
# Write a Python program to create an array of 5 integers and display the array items.
# Access individual element through indexes.
# from array import *
# s=array('i',[1,3,5,7,9])
# for i in s:
# print(i)
# print("Here are the first values:\n")
# print(s[0])
# print(s[1])
# print(s[2])
# Write a Python program to append a new item to the end of the array
# from array import *
# s=array('i',[1,2,3,4])
# s.append(5)
# print("Appending 5 to s:",s)
# Write a Python program to reverse the order of the items in the array
# from array import *
# s=array('i',[1,2,3,4])
# s.reverse()
# print("Reversed",s)
# Write a Python program to get the current memory address and the length in
# elements of the buffer used to hold an array?s contents and also find the size of the memory buffer in bytes.
# from array import *
# s=array('i',[1,2,3,4])
# v=s.buffer_info()
# for i in range(len(s)):
# print(f"The size of {i} element is {v[1]} and address is {v[0]}")
# get number of occurences of a specific element
# from array import *
# s=array('i',[1,2,3,4,3])
# print(s.count(3))
# Write a Python program to append items from inerrable to the end of the array
# from array import *
# s=array('i',[1,2,3,4])
# s.extend(s)
# print(s)
# convert bytes to string
# from array import *
# s=array('b',[99,100,101,102,103,104])
# x=s.tobytes()
# print(x)
# Write a Python program to append items from a specified list.
# from array import *
# s=array('i',[1,2,3,4])
# lis=[5,6,7]
# s.fromlist(lis)
# print(s)
# Write a Python program to insert a new item before the second element in an existing array
# from array import *
# s = array('i', [1, 2, 3, 4])
# s.insert(1,3)
# print(s)
# Write a Python program to remove a specified item using the index from an array
# from array import *
# s=array('i',[1,2,3,4,5])
# s.remove(2)
# print(s)
# Write a Python program to remove the first occurrence of a specified element from an array
# from array import *
# s=array('i',[1,2,3,4,5,1])
# s.remove(1) # it will remove 1's first occurence
# print(s)
# Write a Python program to convert an array to an ordinary list with the same items.
# from array import *
# s=array('i',[1,2,3,4])
# x=s.tolist()
# print(x)
# Write a Python program to find whether a given array of integers contains any duplicate element.
# Return true if any value appears at least twice in the said array and return false if every element is distinct.
# from array import *
# s=array('i',[1,2,3,4,1])
# for i in s:
# if s.count(i)>1:
# print(True)
# exit()
# print(False)
# Write a Python program to find the first duplicate element in a given array of integers.
# Return -1 If there are no such elements.
# from array import *
# s=array('i',[1,2,3,4,1])
# for i in s:
# if s.count(i)>1:
# print(i)
# exit()
# print(-1)