How do I re-map python dict keys

name_map = {‘oldcol1’: ‘newcol1’, ‘oldcol2’: ‘newcol2’, ‘oldcol3’: ‘newcol3’…} for row in rows: # Each row is a dict of the form: {‘oldcol1’: ‘…’, ‘oldcol2’: ‘…’} row = dict((name_map[name], val) for name, val in row.iteritems()) … Or in Python2.7+ with Dict Comprehensions: for row in rows: row = {name_map[name]: val for name, val in row.items()}

How do I easily convert from one collection type to another during a filter, map, flatMap in Scala?

Using breakOut Use breakOut as the CanBuildFrom and let the typer know what you want your result type to be (unfortunately you need to specify String here) scala> import collection.breakOut import collection.breakOut scala> List(1, 2, 3) res0: List[Int] = List(1, 2, 3) scala> res0.map(_.toString)(breakOut) : Vector[String] res2: Vector[String] = Vector(1, 2, 3) Using to[Collection] (starting … Read more

Make dictionary read only in C#

It would be as easy as casting the whole dictionary reference to IReadOnlyDictionary<string, IReadOnlyList<string>> because Dictionary<TKey, TValue> implements IReadOnlyDictionary<TKey, TValue>. BTW, you can’t do that because you want the List<string> values as IReadOnlyList<string>. So you need something like this: var readOnlyDict = (IReadOnlyDictionary<string, IReadOnlyList<string>>)dict .ToDictionary(pair => pair.Key, pair => pair.Value.AsReadOnly()); Immutable dictionaries This is just … Read more

Is there a Python dict without values?

Actually, in Python 2.7 and 3.2+, this really does work: >>> b = {“foo”, “bar”} >>> b set([‘foo’, ‘bar’]) You can’t use [] access on a set (“key into”), but you can test for inclusion: >>> ‘x’ in b False >>> ‘foo’ in b True Sets are as close to value-less dictionaries as it gets. … Read more

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