Advertisement
dRxL

Untitled

Oct 9th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3.  
  4.  
  5. arraycollection =[
  6.   {
  7.     "date":"2015-10-01",
  8.     "color":"blue",
  9.     "number":"5",
  10.     "shape":"round"    
  11.   },
  12.   {
  13.     "date":"2015-10-02",
  14.     "color":"blue",
  15.     "number":"5",
  16.     "shape":"square"
  17.   },
  18.   {
  19.     "date":"2015-10-03",
  20.     "color":"blue",
  21.     "number":"5",
  22.     "shape":"square"  
  23.   },
  24.   {
  25.     "date":"2015-10-04",
  26.     "color":"green",
  27.     "number":"5",
  28.     "shape":"Rectangle"
  29.   },
  30.   {
  31.     "date":"2015-10-05",
  32.     "color":"Blue",
  33.     "number":"5",
  34.     "shape":"Rectangle"
  35.    }
  36. ]
  37.  
  38. def rowfilter(cur, prev):
  39.   outp = {}
  40.   if prev == None:
  41.     return [cur]
  42.    
  43.   differs = 0
  44.   for k in prev.keys():
  45.     if k == 'date':
  46.       outp[k] = cur[k]
  47.       continue
  48.     if k in cur and cur[k] != prev[k]:
  49.       outp[k] = cur[k]
  50.       differs += 1
  51.     else:
  52.       outp[k] = ''
  53.  
  54.   return [outp] if differs > 0 else []
  55.  
  56.  
  57. if __name__ == "__main__":
  58.  
  59.   prev = None
  60.   output = []
  61.   for l in arraycollection:
  62.     output.extend(rowfilter(l, prev))
  63.     prev = l
  64.    
  65.   for l in output:
  66.     print "".join([ k +"=>"+v+",\t" for k, v in l.iteritems()])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement