{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## List Operations" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "2\n", "3\n", "4\n", "5\n", "6\n" ] } ], "source": [ "# Traversing a list \n", "foo = [1, 2, 3, 4, 5, 6]\n", "for element in foo:\n", " print(element)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1, 2, 3, 4, 5, 6, 7]\n" ] } ], "source": [ "# Insert an element\n", "foo = [1, 2, 3, 4, 5, 6]\n", "foo.append(7)\n", "print(foo)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1, 2, 3, 4, 5]\n" ] } ], "source": [ "# Delete an element\n", "foo = [1, 2, 3, 4, 5, 6]\n", "foo.remove(6)\n", "print(foo)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1, 2, 3, 4, 5]\n" ] } ], "source": [ "# Deleting an element using pop\n", "foo = [1, 2, 3, 4, 5, 6]\n", "foo.pop(5) # Here, the pop function takes an index instead of value.\n", "print(foo)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1, 2, 3, 4, 5, 6]\n" ] } ], "source": [ "# Concating two arrays\n", "foo_1 = [1, 2 ,3]\n", "foo_2 = [4, 5, 6]\n", "foo_3 = foo_1 + foo_2\n", "print(foo_3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "interpreter": { "hash": "40d3a090f54c6569ab1632332b64b2c03c39dcf918b08424e98f38b5ae0af88f" }, "kernelspec": { "display_name": "Python 3.8.3 ('base')", "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.8.3" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }