{ "cells": [ { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2\n", "1\n", "3\n", "{'queries': {'queries': [{'keywords': ['design', 'web', 'business', 'startup', 'experience'], 'num_images': 8, 'page': 2, 'id': 'text_only', 'curPage': 4}, {'keywords': ['design', 'web', 'business', 'startup', 'experience'], 'num_images': 8, 'page': 1, 'id': 'image_only', 'curPage': 2}, {'keywords': ['design', 'web', 'business', 'startup', 'experience'], 'num_images': 8, 'page': 3, 'id': 'text_only', 'curPage': 5}]}}\n" ] } ], "source": [ "obj={'queries': {'queries': [{'keywords': ['design', 'web', 'business', 'startup', 'experience'], 'num_images': 8, 'page': 4, 'id': 'text_only', 'curPage': 8}, {'keywords': ['design', 'web', 'business', 'startup', 'experience'], 'num_images': 8, 'page': 2, 'id': 'images_only', 'curPage': 4}, {'keywords': ['design', 'web', 'business', 'startup', 'experience'], 'num_images': 8, 'page': 5, 'id': 'text_only', 'curPage': 9}]}}\n", "\n", "def incrementPages(obj, initialPage):\n", " freqs = {}\n", " for entry in obj['queries']['queries']:\n", " val = freqs.get(entry['id'],0)\n", " freqs.update({entry['id']:val+1})\n", "\n", " for entry in obj['queries']['queries']:\n", " val = freqs.get(entry['id'],False)\n", " if(val):\n", " entry['curPage']=entry['page']+val*initialPage\n", " print(entry['page'])\n", " else:\n", " return {\"error\":\"Error while incrementing query pages\"}\n", " return obj\n", "\n", "print(incrementPages(obj,1))\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "sneakpic", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 2 }