Python: How to merge two dictionaries

# How to merge two dictionaries
# in Python 3.5+

>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 3, 'c': 4}

>>> z = {**x, **y}

>>> z
{'c': 4, 'a': 1, 'b': 3}

# In Python 2.x you could
# use this:
>>> z = dict(x, **y)
>>> z
{'a': 1, 'c': 4, 'b': 3}

# In these examples, Python merges dictionary keys
# in the order listed in the expression, overwriting 
# duplicates from left to right.

Scala: Traits

A trait encapsulates method and field definitions, which can then be reused by mixing them into classes. Unlike class inheritance, in which each class must inherit from just one superclass, a class can mix in any number of traits.

Traits are used to define object types by specifying the signature of the supported methods. Scala also allows traits to be partially implemented but traits may not have constructor parameters.

A trait definition looks just like a class definition except that it uses the keyword trait. The following is the basic example syntax of trait.


trait Equal {
   def isEqual(x: Any): Boolean
   def isNotEqual(x: Any): Boolean = !isEqual(x)

This trait consists of two methods isEqual and isNotEqual. Here, we have not given any implementation for isEqual where as another method has its implementation. Child classes extending a trait can give implementation for the un-implemented methods. So a trait is very similar to what we have abstract classes in Java.

Scala : Closure program

closure is a function, whose return value depends on the value of one or more variables declared outside this function.

The following piece of code with anonymous function.

val multiplier = (i:Int) => i * 10

Here the only variable used in the function body, i * 10 , is i, which is defined as a parameter to the function. Try the following code −

val multiplier = (i:Int) => i * factor

There are two free variables in multiplier: i and factor. One of them, i, is a formal parameter to the function. Hence, it is bound to a new value each time multiplier is called. However, factor is not a formal parameter, then what is this? Let us add one more line of code.

var factor = 3
val multiplier = (i:Int) => i * factor

Now factor has a reference to a variable outside the function but in the enclosing scope. The function references factor and reads its current value each time. If a function has no external references, then it is trivially closed over itself. No external context is required.

Try the following example program.


object Closure {
   def main(args: Array[String]) {
      println( "multiplier(1) value = " +  multiplier(1) )
      println( "multiplier(2) value = " +  multiplier(2) )
   var factor = 3
   val multiplier = (i:Int) => i * factor


A beautiful cross platform Desktop Player for Google Play Music

Download link:!

Google Play Music Desktop Player is open source on GitHub. This means YOU, the community, gets a say in all the features we implement and you can even get involved and help out.

If you find a bug or want something new, tell us in Gitter or on GitHub and we will see what we can do!!

List A Directory With Tree Command On Mac OS X

First, if you don’t have Homebrew, install it first.

Run the following command to install the tree command:-


➜ brew install tree
 ==> Downloading
 ######################################################################## 100.0%
 ==> Pouring tree-1.7.0.sierra.bottle.1.tar.gz
 🍺 /usr/local/Cellar/tree/1.7.0: 7 files, 113.3KB

➜ DesignPatternsJava9 git:(object-inheritance-issues) ✗ tree
 └── inheritance
 ├── inheritance
 │   └── production
 │   └── Client.class
 ├── inheritance.iml
 ├── production
 │   └── Client.class
 ├── src
 │   ├──
 │   └──
 └── test
 └── inheritance
 ├── Client.class
 ├── inheritance.iml
 └── inheritanceIssues.iml

7 directories, 9 files

High level of triglycerides can increase your risk of heart

What are triglycerides?

Triglycerides are a type of fat (lipid) found in your blood. When you eat, your body converts any calories it doesn’t need to use right away into triglycerides. The triglycerides are stored in your fat cells. Later, hormones release triglycerides for energy between meals. If you regularly eat more calories than you burn, particularly “easy” calories like carbohydrates and fats, you may have high triglycerides (hypertriglyceridemia).

What’s considered normal?

A simple blood test can reveal whether your triglycerides fall into a healthy range.

  • Normal — Less than 150 milligrams per deciliter (mg/dL), or less than 1.7 millimoles per liter (mmol/L)
  • Borderline high — 150 to 199 mg/dL (1.8 to 2.2 mmol/L)
  • High — 200 to 499 mg/dL (2.3 to 5.6 mmol/L)
  • Very high — 500 mg/dL or above (5.7 mmol/L or above)

What’s the difference between triglycerides and cholesterol?

Triglycerides and cholesterol are separate types of lipids that circulate in your blood. Triglycerides store unused calories and provide your body with energy, and cholesterol is used to build cells and certain hormones. Because triglycerides and cholesterol can’t dissolve in blood, they circulate throughout your body with the help of proteins that transport the lipids (lipoproteins).

Good Design vs Bad Design – Information overload

The Bad: Parking Signs in Los Angeles

Parking signs in Los Angeles (LA) have been the epitome of information overload for decades. They’ve always been notoriously hard to understand, because the traffic rules are complex, resulting in the need to convey a lot of information in a small area.

How confusing are these signs? Traditionally, very—look at this example from the 2010s:

Author/Copyright holder: Jorge Gonzalez. Copyright terms and licence: CC BY-SA 2.0

As LA parking signs go, this example is already a pretty simple one.

Imagine you are a driver along this road on a Tuesday morning at 9 a.m. Can you park at this spot? What sounds like a simple question takes a lot of mental processing to answer.

As designers, we’re often faced with situations where we have to design for a lot of information to be displayed in a small space. The parking signs in LA might be an extreme case, but many times designing for mobile apps means facing the same problems. Is there a way out—for both the parking signs and designers in general?

The Good: Nikki Sylianteng’s Parking Sign

Designing a sign to display all the information, while being easy to understand, sounds like an impossible task. But that’s exactly what Brooklyn designer Nikki Sylianteng did.

Author/Copyright holder: Nikki Sylianteng. Copyright terms and licence: CC BY-NC-SA 4.0

Nikki’s proposed parking sign was eventually used in LA as part of a trial run.

Part of why Nikki’s design1 works well is that it is user-centred: Nikki realised drivers simply want to know whether they can park at a spot. Yes or no—that’s all drivers needed, and that’s all the parking sign shows.

Her design also made use of visuals, rather than text, to convey information. The result is incredibly intuitive: green for OK, red for No Parking. It’s even designed for the colour blind, with stripes for No Parking.

Now when you look at the sign, you’ll know that on Tuesday at 9 a.m., parking is not allowed. The bars show what’s what at a glance—simple.

Lessons Learnt: Best Practice

  • Understand what your users need, then design based on that. This helps reduce information overload.
  • Have lots of information to convey to your users? Try using visuals instead of text. Learn more about data visualisation here.