Phase 4 - Level 3: Transformation
Transform arrays - reverse, rotate, swap, and create new arrays.
10 programs · open one, then the next
Start with New Array of Squares- 01New Array of SquaresIntermediateCreate a separate list of squares with append. Students preserve original values, transform every element once, and compare the two displayed lists afterward.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 02New Array with Only Even ElementsIntermediateBuild a new list containing only even values in Python. Students filter without altering the source and preserve the order and repetitions of matching elements.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 03Replace Negatives with 0IntermediateReplace negative list entries with zero in Python. Students use indexes for in-place updates and distinguish changing an element from changing a loop variable.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 04Replace Evens with 1, Odds with 0IntermediateEncode even list values as one and odd values as zero in Python. Students trace in-place index assignments and avoid confusing this rule with remainder itself.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 05Swap First & Last ElementsIntermediateSwap a list's first and last elements safely. Students use a nonempty guard, negative indexing, and simultaneous assignment without overwriting either endpoint.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 06Reverse ArrayIntermediateReverse a Python list by swapping symmetric positions. Students trace a half-length loop and calculate the partner index without swapping every pair twice.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 07Rotate Left by 1IntermediateRotate a Python list one position left with manual shifts. Students save the first value, move remaining values safely, and wrap the saved value to the end.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 08Rotate Right by 1IntermediateRotate a list one position right with manual shifts. Students preserve the last value and scan backward to avoid overwriting values that are still needed.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 09Swap Alternate ElementsIntermediateSwap adjacent pairs in a Python list with a step-two loop. Students trace safe partner indexes and see why an unmatched final element stays in place.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):
- 10Copy Array ManuallyIntermediateCopy integer list elements manually with append. Students create a list container and distinguish a copied list from a second reference to the same list.Open example →py# Take array n = int(input("Enter array size: ")) arr = [] for i in range(n):