Map() with lambda


#1

This is from external reading part of Advanced Topics in Python.

http://www.secnetix.de/olli/Python/lambda_functions.hawk

Code I wrote is printing correct mount points for some directories. For others that have mount point as 3rd sub string, it is not working. How to formulate lambda correctly for this map() function?

Output:
['/', '/dev', 'on', 'on', '/Volumes/MySQL', '/Volumes/Sublime', '/Volumes/Sublime']
this 'on' is coming from:
'map auto_home on /home (autofs, automounted, nobrowse)'

My code is below.

'''unix command to find mount points in the file system'''
import subprocess

mount = subprocess.check_output(["mount", "-v"])
lines = mount.split("\n") [:-1]
print(lines)
points = map(lambda word: word.split()[2], lines)
print(points)

---------
For the line: 'map auto_home on /home (autofs, automounted, nobrowse)' 
2nd substring is 'on' and not '/home' as i wanted.
How to re-write the lambda function with map()?
I need something like:
if word[0] == 'map':
       word =  word.split()[3]
else:
       word = word.split()[2]

thank you!


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.