Java time-based map/cache with expiring keys [closed]

Yes. Google Collections, or Guava as it is named now has something called MapMaker which can do exactly that. ConcurrentMap<Key, Graph> graphs = new MapMaker() .concurrencyLevel(4) .softKeys() .weakValues() .maximumSize(10000) .expiration(10, TimeUnit.MINUTES) .makeComputingMap( new Function<Key, Graph>() { public Graph apply(Key key) { return createExpensiveGraph(key); } }); Update: As of guava 10.0 (released September 28, 2011) many … Read more

Pandas DataFrame to List of Dictionaries

Use df.to_dict(‘records’) — gives the output without having to transpose externally. In [2]: df.to_dict(‘records’) Out[2]: [{‘customer’: 1L, ‘item1’: ‘apple’, ‘item2’: ‘milk’, ‘item3’: ‘tomato’}, {‘customer’: 2L, ‘item1’: ‘water’, ‘item2’: ‘orange’, ‘item3’: ‘potato’}, {‘customer’: 3L, ‘item1’: ‘juice’, ‘item2’: ‘mango’, ‘item3’: ‘chips’}]

How to check if a value exists in a dictionary?

>>> d = {‘1’: ‘one’, ‘3’: ‘three’, ‘2’: ‘two’, ‘5’: ‘five’, ‘4’: ‘four’} >>> ‘one’ in d.values() True Out of curiosity, some comparative timing: >>> T(lambda : ‘one’ in d.itervalues()).repeat() [0.28107285499572754, 0.29107213020324707, 0.27941107749938965] >>> T(lambda : ‘one’ in d.values()).repeat() [0.38303399085998535, 0.37257885932922363, 0.37096405029296875] >>> T(lambda : ‘one’ in d.viewvalues()).repeat() [0.32004380226135254, 0.31716084480285645, 0.3171098232269287] EDIT: And in case … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)