{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Trainer:\n",
    "    \n",
    "Md. Jalal Uddin, Founder and director of Research Society https://researchsociety20.org/founder-and-director/\n",
    "\n",
    "email: 20205103002@nuist.edu.cn, dmjalal90@gmail.com"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Lists\n",
    "\n",
    "By placing all the items (elements) inside square brackets []\n",
    "\n",
    "and separated by commas (,), we can create a list in Python."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "jalal\n",
      "Ripa\n",
      "6\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "list_item  = ['jalal','Ripa', 2, 4, 6]\n",
    "    \n",
    "print(list_item[0])    # returns the first item\n",
    "\n",
    "print(list_item[1])    # returns the second item\n",
    "\n",
    "print(list_item[-1])   # returns the first item from the end\n",
    "\n",
    "print(list_item[-2])   # returns the second item from the end\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['jalal', 'Ripa', 2, 4, 6, ['jalal', 'Ripa', 2, 4, 6]]\n"
     ]
    }
   ],
   "source": [
    "list_item1 = ['jalal','Ripa', 2, 4, 6]\n",
    "\n",
    "list_item.append(list_item1)  # append() method appends an element to the end of the list\n",
    "print(list_item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['jalal', 'Ripa', 'Tamim', 2, 4, 6, ['jalal', 'Ripa', 2, 4, 6]]\n"
     ]
    }
   ],
   "source": [
    "list_item.insert(2,'Tamim')  # insert() method inserts the specified value at the specified position\n",
    "print(list_item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['jalal', 'Ripa', 2, 4, 6, ['jalal', 'Ripa', 2, 4, 6]]\n"
     ]
    }
   ],
   "source": [
    "list_item.remove('Tamim')  \n",
    "print(list_item) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['jalal', 'Ripa', 2, 4, 6]\n"
     ]
    }
   ],
   "source": [
    "list_item.pop()      # removes the last item   \n",
    "print(list_item) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "list_item.clear()      # removes all the items \n",
    "print(list_item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Ripa', 2, 4, 6]\n",
      "[2, 4, 6]\n"
     ]
    }
   ],
   "source": [
    "list_item3 = ['jalal','Ripa', 2, 4, 6]\n",
    "list_item4 = ['jalal','Ripa', 2, 4, 6]\n",
    "\n",
    "del list_item3[0]       #  item can be deleted by index \n",
    "print(list_item3)\n",
    "\n",
    "del list_item4[0:2]     #  item can be deleted by slice\n",
    "print(list_item4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Jimi', 'Ripa', 'jalal']\n"
     ]
    }
   ],
   "source": [
    "list_item  = ['jalal','Ripa','Jimi']\n",
    "\n",
    "list_item.sort()      # sorts the list\n",
    "print(list_item)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5]\n"
     ]
    }
   ],
   "source": [
    "numbers = [1,3,2,5,4]\n",
    "\n",
    "numbers.sort()      # sorts the list\n",
    "print(numbers) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 4, 3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "numbers.reverse() # reverses the list\n",
    "print(numbers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 4, 3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "new_number = numbers.copy()  # make a copy of the list\n",
    "print(new_number)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
