{ "cells": [ { "cell_type": "markdown", "id": "001d5e42", "metadata": {}, "source": [ "# Extract Sublist" ] }, { "cell_type": "code", "execution_count": null, "id": "4dca2369", "metadata": {}, "outputs": [], "source": [ "\"\"\"\n", " Extract a sublist and add list together\n", "\"\"\"\n", "\n", "def main():\n", "\n", " # Make two lists\n", " a_list = [1,2,3,4,5,6,7,8]\n", " b_list = [9,10,11,12,13]\n", "\n", " # Make a third list being a_list + elements 3,4,5 of b_list\n", " c_list = a_list + b_list[3:6]\n", " print(\"The c_list is : \" + str(c_list) + \" of length \" + str(len(c_list)))\n", "\n", " # Make a fourth list being elements 4:end of a + 0,1,2 of list b\n", " d_list = a_list[4:] + b_list[:3]\n", " print(\"The d_list is : \" + str(d_list) + \" of length \" + str(len(d_list)))\n", "\n", "\n", "\n", "main()\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }