{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = (17, 21)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "(a,b) = t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "(a,b) = (27, 31)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "27\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "31\n"
     ]
    }
   ],
   "source": [
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "a, b = 37, 41"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "37\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "41\n"
     ]
    }
   ],
   "source": [
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type((a,b))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Problem 1 (not involving lambda):\n",
    "• You’re given an array a of random integers from 1 to 1000\n",
    "• Let b be a copy of a, but sorted in ascending order\n",
    "• Print b (edited) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  Let c be a copy of a, \n",
    "# but sorted by how many of the digit 5 each number has (it gets listed first if it has more 5s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-56-a377cf8efed1>, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-56-a377cf8efed1>\"\u001b[0;36m, line \u001b[0;32m5\u001b[0m\n\u001b[0;31m    three_fives = for\u001b[0m\n\u001b[0m                    ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "a = random.sample(range(1, 1000), 100)\n",
    "b = sorted(a)\n",
    "get_fives = lambda x: [int(i) for i in str(x) if i == '5']\n",
    "three_fives = []\n",
    "two_fives = []\n",
    "one_five = []\n",
    "zero_fives = []\n",
    "for num in a:\n",
    "    if len(get_fives(num)) == 3:\n",
    "        three_fives.append(num)\n",
    "    elif len(get_fives(num)) == 2:\n",
    "        two_fives.append(num)\n",
    "    elif len(get_fives(num)) == 1:\n",
    "        one_five.append(num)\n",
    "    else:\n",
    "        zero_fives.append(num)\n",
    "c = sorted(three_fives) + sorted(two_fives) + sorted(one_five) + sorted(zero_fives)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{365: 1}]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_fives = lambda x: [{x: 1} for i in str(x) if i == '5']\n",
    "get_fives(365)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "# c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "# sum(1 for y in x if y > 2)\n",
    "import random\n",
    "a = random.sample(range(1, 1000), 100)\n",
    "b = sorted(a)\n",
    "get_f = lambda x: {x: sum(1 for i in str(x) if i == '5')}\n",
    "get_f(356)\n",
    "c = [get_f(num) for num in a]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[558,\n",
       " 505,\n",
       " 535,\n",
       " 125,\n",
       " 257,\n",
       " 528,\n",
       " 152,\n",
       " 510,\n",
       " 305,\n",
       " 574,\n",
       " 758,\n",
       " 587,\n",
       " 583,\n",
       " 145,\n",
       " 579,\n",
       " 405,\n",
       " 560,\n",
       " 475,\n",
       " 352,\n",
       " 523,\n",
       " 845,\n",
       " 275,\n",
       " 495,\n",
       " 356,\n",
       " 450,\n",
       " 539,\n",
       " 544,\n",
       " 582,\n",
       " 189,\n",
       " 294,\n",
       " 498,\n",
       " 486,\n",
       " 631,\n",
       " 891,\n",
       " 969,\n",
       " 671,\n",
       " 311,\n",
       " 196,\n",
       " 290,\n",
       " 966,\n",
       " 300,\n",
       " 407,\n",
       " 393,\n",
       " 781,\n",
       " 116,\n",
       " 91,\n",
       " 26,\n",
       " 860,\n",
       " 870,\n",
       " 636,\n",
       " 270,\n",
       " 872,\n",
       " 148,\n",
       " 436,\n",
       " 343,\n",
       " 419,\n",
       " 37,\n",
       " 180,\n",
       " 734,\n",
       " 183,\n",
       " 773,\n",
       " 240,\n",
       " 219,\n",
       " 791,\n",
       " 617,\n",
       " 763,\n",
       " 913,\n",
       " 403,\n",
       " 182,\n",
       " 678,\n",
       " 106,\n",
       " 349,\n",
       " 747,\n",
       " 723,\n",
       " 930,\n",
       " 40,\n",
       " 788,\n",
       " 832,\n",
       " 302,\n",
       " 607,\n",
       " 363,\n",
       " 889,\n",
       " 766,\n",
       " 662,\n",
       " 317,\n",
       " 646,\n",
       " 289,\n",
       " 377,\n",
       " 871,\n",
       " 438,\n",
       " 278,\n",
       " 12,\n",
       " 32,\n",
       " 96,\n",
       " 318,\n",
       " 236,\n",
       " 801,\n",
       " 479,\n",
       " 364,\n",
       " 82]"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sorted(a, key=lambda x: sum(1 for i in str(x) if i == '5'), reverse=True)"
   ]
  },
  {
   "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
