DEV Community

Cover image for Python challenge_16
Mahmoud EL-kariouny
Mahmoud EL-kariouny

Posted on


Python challenge_16

Writing short code

Define a function named convert that takes a list of numbers
as its only parameter and returns a list of each number converted to a string.

For example:

the call convert([1, 2, 3]) should return ["1", "2", "3"].

What makes this tricky is that your function body must only contain a single line of code.

Task URI

My solution

def convert(lists): return [str(con_list) for con_list in lists]
print(convert([1, 2, 3]))
Enter fullscreen mode Exit fullscreen mode

Another solution

def convert(ns):
    return [str(n) for n in ns]
Enter fullscreen mode Exit fullscreen mode

using map

def convert(ns):
    return list(map(str, ns))
Enter fullscreen mode Exit fullscreen mode

All the best to you.

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.