Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e266836

Browse files
Source Code
1 parent 2de33e4 commit e266836

15 files changed

+121
-0
lines changed

‎Append_Inerrable_Array.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write a Python Program to Append Items from Inerrable to the End of the Array.
2+
from array import *
3+
array_num = array('i', [1, 3, 5, 7, 9])
4+
print("Original Array: " + str(array_num))
5+
array_num.extend(array_num)
6+
print("Extended Array: " + str(array_num))

‎Append_Item_Array.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write a Python Program to Append a new item to the end of the Array.
2+
from array import *
3+
array_num = array('i', [1, 3, 5, 7, 9])
4+
print("Original Array: " + str(array_num))
5+
print("Append 11 at the end of the Array: ")
6+
array_num.append(11)
7+
print("New Array: " + str(array_num))

‎Append_Items_Specified_List.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Write a Python Program to Append Items from a Specified List.
2+
3+
from array import *
4+
num_list = [1, 2, 6, -8]
5+
array_num = array('i', [])
6+
print("Items in the List: " + str(num_list))
7+
print("Append Items from the List: ")
8+
array_num.fromlist(num_list)
9+
print("Items in the Array: " + str(array_num))

‎Array_Internal_Representation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write a Python Program to get the length in bytes of one array item in the Internal Representation.
2+
3+
from array import *
4+
array_num = array('i', [1, 3, 5, 7, 9])
5+
print("Original Array: " + str(array_num))
6+
print("Length in Bytes of One Array Item: " + str(array_num.itemsize))

‎Convert_Array.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write a Python Program to Convert an Array to an Ordinary List with the Same Items.
2+
from array import *
3+
array_num = array('i', [1, 3, 5, 3, 7, 1, 9, 3])
4+
print("Original Array: " + str(array_num))
5+
num_list = array_num.tolist()
6+
print("Convert the Said Array to an Ordinary List with the Same Items:")
7+
print(num_list)

‎Convert_Array_Machine_Value.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write a Python Program to Convert an Array to an Array of Machine Values and Return the Bytes Representation.
2+
from array import *
3+
print("Bytes to String: ")
4+
x = array('b', [119, 51, 114, 101, 115, 111, 117, 114, 99, 101])
5+
s = x.tobytes()
6+
print(s)

‎Display_Five_Integers_Array.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
''' Write a Python Program to create an array of 5 integers and display the array items. Access individual
2+
element through indexes. '''
3+
4+
from array import *
5+
array_num = array('i', [1,3,5,7,9])
6+
for i in array_num:
7+
print(i)
8+
print("Access First Three Items Individually:")
9+
print(array_num[0])
10+
print(array_num[1])
11+
print(array_num[2])

‎Duplicate_Element_Array.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Write a Python Program to Find Whether a Given Array of Integers Contains Any Duplicate Element.
2+
'''Return true if any appears at least twice in the said array and return false if every element is distinct.'''
3+
4+
def test_duplicate(array_nums):
5+
nums_set = set(array_nums)
6+
return len(array_nums) != len(nums_set)
7+
print(test_duplicate([1,2,3,4,5]))
8+
print(test_duplicate([1,2,3,4,4]))
9+
print(test_duplicate([1,1,2,2,3,3,4,4,5]))

‎First_Duplicate_Element.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Write a Python Program to find the First Duplicate Element in a Given Array of Integers.
2+
''' Return -1 if there are no such elements.'''
3+
4+
def find_first_duplicate(nums):
5+
num_set = set()
6+
no_duplicate = -1
7+
8+
for i in range(len(nums)):
9+
10+
if nums[i] in num_set:
11+
return nums[i]
12+
else:
13+
num_set.add(nums[i])
14+
15+
return no_duplicate
16+
17+
print(find_first_duplicate([1,2,3,4,4,5]))
18+
print(find_first_duplicate([1,2,3,4]))
19+
print(find_first_duplicate([1,1,2,3,3,2,2]))

‎Insert_Existing_Array.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write a Python Program to Insert a New Item Before the Second Element in an Existing Array.
2+
from array import *
3+
array_num = array('i', [1, 3, 5, 7, 9])
4+
print("Original Array: " + str(array_num))
5+
print("Insert New Value 4 Before 3: ")
6+
array_num.insert(1, 4)
7+
print("New Array: " + str(array_num))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /