File size: 2,449 Bytes
a3b1677
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
 "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
}