For this week six optional advanced exercise, I expanded my practice with Python and R by working through a series of tasks involving variables, casting, data structures, list processing, and basic algorithm design. I explored Python’s dynamic typing and used casting to resolve type‑related issues.
I created and separated mixed‑type lists, compared core Python data structures, and reviewed specialized types such as datetime and collections. I also wrote functions to separate positive and negative integers, generate the Fibonacci sequence, and sort data within a DataFrame. In R, I implemented matching while and for loops to reinforce iterative logic. This exercise strengthened my understanding of cross‑language concepts, improved my confidence in writing clean and structured code, and deepened my familiarity with Python and R as analytical tools.
Python Section - Week6_Advance_Exercise_Python-ipynb
• Explanation of dynamic typing and casting
• Mixed list separation
• Comparison of lists, tuples, sets, dictionaries
• Comparison of specialized types (, )
• Function to separate positive/negative integers
• DataFrame creation and filtering
• Fibonacci function
• Sorting integers in a DataFrame
R Section
• Matching while and for loops
Google Colab version - Week6_Advance_Exercise.R
Here is a summary of the outputs:
- Variable Casting and Concatenation: The integer 1 was cast to a string and concatenated with the string 'one', resulting in ’one'.
- List Separation: A mixed list [3, 'S', 'B', 21] was successfully separated into a stringList (['S', 'B']) and an intList ([3, 21]).
- Positive/Negative Separation: The separatePosNeg function correctly separated the input [3, -3, 4, -5] into positive numbers [3, 4] and negative numbers [-3, -5].
- DataFrame Operations: A Pandas DataFrame was created from mixedList. It was then filtered to show only integer values and only string values, demonstrating how to manage mixed data types in DataFrames.
- Fibonacci Sequence: The fibonacci function generated the first 10 numbers of the Fibonacci sequence: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34].
- DataFrame Sorting: A DataFrame df2 created with a list of numbers [9, 2, 15, 1, 7] and then successfully sorted by the 'numbers' column in ascending order.
The final <IPython.core.display.Markdownobject> indicates that the R code section (which was commented out and for reference) was successfully displayed as Markdown in the notebook.
Conclusion
This advanced exercise provided additional practice with Python and R, reinforcing my understanding of data structures, iteration, casting, and algorithmic thinking. It also helped me compare how both languages handle loops, data types, and list operations.
References for Week Six Advanced Exercise
Python Software Foundation. (2024). The Python 3 documentation.
https://docs.python.org/3/
Python Software Foundation. (2024). Built-in types.https://docs.python.org/3/library/stdtypes.html (docs.python.org in Bing)
Python Software Foundation. (2024). Data structures — list, tuple, set, dict.https://docs.python.org/3/tutorial/datastructures.html (docs.python.org in Bing)
Python Software Foundation. (2024). datetime — Basic date and time types.https://docs.python.org/3/library/datetime.html (docs.python.org in Bing)
Python Software Foundation. (2024). collections — Container datatypes.https://docs.python.org/3/library/collections.html (docs.python.org in Bing)
Pandas Development Team. (2024). pandas’ documentation.
https://pandas.pydata.org/docs/
Wikipedia contributors. (2024). Fibonacci number. Wikipedia.
https://en.wikipedia.org/wiki/Fibonacci_number
R Core Team. (2024). R language definition.https://cran.r-project.org/manuals.html (cran.r-project.org in Bing)
(With the assistance of Microsoft CoPilot)