Merge Two Arrays
Merge two lists by concatenation. Students follow input collection and understand why combining sequences does not sort values or remove repeated entries.
1# Take first array2n1 = int(input("Enter size of first array: "))3arr1 = []4for i in range(n1):5 arr1.append(int(input(f"Array1 element {i+1}: ")))67# Take second array8n2 = int(input("Enter size of second array: "))9arr2 = []10for i in range(n2):11 arr2.append(int(input(f"Array2 element {i+1}: ")))1213# Merge14merged = arr1 + arr215print(f"Merged array: {merged}")
Output
Enter size of first array: 3 Array1 element 1: 1 Array1 element 2: 2 Array1 element 3: 3 Enter size of second array: 2 Array2 element 1: 4 Array2 element 2: 5 Merged array: [1, 2, 3, 4, 5]
In this one
- Concatenate sequences
- Preserve each input block
- Distinguish merge from sorting
How it works
- 1
Collect arr1 and arr2.
- 2
Create merged with arr1 + arr2.
- 3
Print the new list without modifying either source.
Edge cases
Does this sort the result?
Does this sort the result?
No. It concatenates in input order.
What if both lists are empty?
What if both lists are empty?
The merged list is empty.
What's going on
arr1 + arr2 creates a new list with all first-list entries followed by all second-list entries.
This merge is concatenation, not the ordered merge step from merge sort. Original list order is preserved within each block and duplicates remain. An empty input list contributes no entries, while the other list still appears in full.
Does this sort the result? No. It concatenates in input order.
What if both lists are empty? The merged list is empty.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which entries come first?
Pick an answer to check it.
Question 2
Does this sort the result?
Pick an answer to check it.
Questions people ask
Does this sort the result?
No. It concatenates in input order.
What if both lists are empty?
The merged list is empty.
Which entries come first?
All entries of arr1.
๐Related Content
- ๐
Phase 4 - Learn Concepts
Review Phase 4 concepts and explanations
- ๐
Phase 4 - Quiz
Test your Phase 4 understanding with quiz questions
- ๐ป
Phase 4 - All Practice Problems
Explore all practice problems for Phase 4
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum