Python 에서 리스트(List)에 값은 함수를 적용하고 싶을 때 map 함수를 사용하면 됩니다.

예제 소스로 확인해 봅시다.

def plus(x):
    return x+x
 
lst = [1,2,3,4,5,6,7,8,9, "A", "B", "C"]
 
print map(plus, lst)

결과는 다음과 같습니다.

[2, 4, 6, 8, 10, 12, 14, 16, 18, 'AA', 'BB', 'CC']
[Finished in 0.1s]

Naming

module_name, package_name, ClassName, method_name, ExceptionName, function_name, GLOBAL_CONSTANT_NAME, global_var_name, instance_var_name, function_parameter_name, local_var_name.

Names to Avoid

single character names except for counters or iterators

dashes (-) in any package/module name

__double_leading_and_trailing_underscore__ names (reserved by Python)

Naming Convention

"Internal" means internal to a module or protected or private within a class.

Prepending a single underscore (_) has some support for protecting module variables and functions (not included with import * from). Prepending a double underscore (__) to an instance variable or method effectively serves to make the variable or method private to its class (using name mangling).

Place related classes and top-level functions together in a module. Unlike Java, there is no need to limit yourself to one class per module.

Use CapWords for class names, but lower_with_under.py for module names. Although there are many existing modules named CapWords.py, this is now discouraged because it's confusing when the module happens to be named after a class. ("wait -- did I write import StringIO or from StringIO import StringIO?")

Guidelines derived from Guido's Recommendations

Type Public Internal

Packages lower_with_under

Modules lower_with_under _lower_with_under

Classes CapWords _CapWords

Exceptions CapWords

Functions lower_with_under() _lower_with_under()

Global/Class Constants CAPS_WITH_UNDER _CAPS_WITH_UNDER

Global/Class Variables lower_with_under _lower_with_under

Instance Variables lower_with_under _lower_with_under (protected) or __lower_with_under (private)

Method Names lower_with_under() _lower_with_under() (protected) or __lower_with_under() (private)

Function/Method Parameters lower_with_under

Local Variables lower_with_under

Main

+ Recent posts