List mapping is a very useful way to transform data by applying a function to each element of the list, and you can use a strategy or method to traverse the calculation of each element.
For example:
params = {"Server": "Mpilgrim", "database": "Master", " uid": "sa", "pwd": "Secret" }print ["%s=%s"% (k , Params[k]) for K in Params.keys ()]print '; '. The Join (["%s=%s"% (k, params[k]) for K in Params.keys ()]) returns the result: [' Uid=sa ', ' pwd=secret ', ' database=master ', ' server= ' Mpilgrim '] can also be improved by converting tuples into strings, using the Join function method. ' Uid=sa;pwd=secret;database=master;server=mpilgrim ' (the Join function is not only used for tuples but also for lists, function is String) split is the opposite of join, convert string to Narimoto group to see the following application <pre name= "code" class= "python" >>>> <span style= "font-family:arial, Helvetica, Sans-serif;" >str = ' Server=mpilgrim;uid=sa;database=master;pwd=secret ' </span>
>>> Str.split (';')
[' Server=mpilgrim ', ' uid=sa ', ' database=master ', ' Pwd=secret ']
>>> str.split ('; ', 1)
[' Server=mpilgrim ', ' Uid=sa;database=master;pwd=secret ']
>>> str.split ('; ', 2)
[' Server=mpilgrim ', ' uid=sa ', ' Database=master;pwd=secret ']
List map Use cases:
>>> Li = [1, 9, 8, 4]>>> [elem*2 for Elem in Li] 1[2,, 8]>>> li[1, 9, 8, 4]