Skip to content

Latest commit

 

History

History
47 lines (23 loc) · 727 Bytes

Building_Strings_From_a_Hash.md

File metadata and controls

47 lines (23 loc) · 727 Bytes

CodeWars Python Solutions


Building Strings From a Hash

Complete the solution so that it takes the object (JavaScript/CoffeeScript) or hash (ruby) passed in and generates a human readable string from its key/value pairs.

The format should be "KEY = VALUE". Each key/value pair should be separated by a comma except for the last pair.

Examples

solution({"a": 1, "b": '2'}) # should return "a = 1,b = 2"

Given Code

def solution(pairs):
    pass

Solution

def solution(pairs):
    return ",".join(sorted(["{} = {}".format(k,v) for k,v in pairs.items()]))

See on CodeWars.com