{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "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": 20,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-20-a1e314544214>, line 7)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  File \u001b[0;32m\"<ipython-input-20-a1e314544214>\"\u001b[0;36m, line \u001b[0;32m7\u001b[0m\n\u001b[0;31m    three_fives = [[num if (sum(1 for i in str(num) if i == '5') == 2)] for num in a]\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",
    "# def get_fives(num, limit):\n",
    "#     if int(i) for i in str(x) if i == '5'\n",
    "    \n",
    "three_fives = [[num if (sum(1 for i in str(num) if i == '5') == 2)] for num in a]\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)\n",
    "three_fives"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "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
}
