{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# List Operations" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "55.0\n" ] } ], "source": [ "number_of_inputs = int(input())\n", "\n", "\n", "max = 0 \n", "while number_of_inputs > 0:\n", " i = float(input())\n", " if i > max:\n", " max = i\n", " number_of_inputs -= 1\n", "print(max)\n", "\n", "\n", "# list_of_inputs = []\n", "# while number_of_inputs > 0:\n", "# i = float(input())\n", "# list_of_inputs.append(i)\n", "# number_of_inputs -= 1\n", "\n", "# list_of_inputs.sort(reverse=True)\n", "# print(list_of_inputs[0])\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 2, 3, 6, 7]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l = [1,2,3,2,3,6]\n", "l.append(7)\n", "l" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.count(3)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 2, 3, 6, 7, 7, 8, 7]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.extend([7,8,7])\n", "l" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.index(7) # first occurance index of the specified value" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 10, 2, 3, 2, 3, 6, 7, 7, 8, 7]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.insert(1,10) # position, element\n", "l" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 2, 3, 6, 7, 7, 8, 7]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.pop(1) # index remove element\n", "l" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 2, 3, 6, 7, 7, 8, 7]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.remove(3) # removes first occurance of specified element\n", "l" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[7, 8, 7, 7, 6, 3, 2, 2, 1]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l.reverse() # reverse the list\n", "l" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "l.sort() # sort the list" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "l.clear() # clean the list" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['H', 'e', 'l', 'l', 'o', 'I', 'a', 'm', 'n', 'i', 's', 'h', 'a', 'n', 't']" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l = list(\"Hello I am nishant\".replace(\" \",\"\"))\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.3 64-bit ('anaconda3': conda)", "language": "python", "name": "python38364bitanaconda3conda5a21e7c9305747559a413d7622491a2e" }, "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" } }, "nbformat": 4, "nbformat_minor": 4 }