Q:

How can i use os.path.join in map()

I have a list of directory name and want to add a fixed path before it.
I am aware that, it can be done in two ways, 1) Using for loop and 2) using map() function.
I was able to do using for loop:
dirNames = ['dir1', 'dir2']
dirsFullPath = [os.path.join('C:\\', dir) for dir in dirNames]

But with map how to pass two parameters i.e. 'C:\' and directory name for every directory name in list.
dirsFullPath = map(os.path.join, dirNames) # so where to put 'C:\\' in this line.

A:

You need to pass a function and an iterable to map, for application as simple as this, you can rely on a lambda function and the iterable being your list.
import os
dirNames = ['dir1', 'dir2']
path_maker = lambda dir_name: os.path.join("C:\\", dir_name)
map(path_maker, dirNames)

Refer to the documentation of map for further detail, https://docs.python.org/2/library/functions.html#map

