본문 바로가기
Python(Eng. ver)

11. Collections and Loops

by 곽정우 2024. 3. 15.

1. List and For loops:

A loop is a control structure used to execute the same task repeatedly. The most commonly used loops are the for loop and the while loop, each suited for different situations.

 

2. Dictionaries and For loops

 

3. Comprehensions

Comprehension is one of the simple ways to create or transform collections such as lists, sets, and dictionaries in Python. Comprehension is a technique for creating collections concisely using loops and conditionals, helping user write simpler and more readable code.

 

3-1. List Comprehensions

  • Filtering or transforming elements of an existing list based on certain conditions to create a new list succinctly.
  • It enhances the efficiency of data processing tasks and improves code conciseness.

 

3-2. Set Comprehensions

  • It allow user to create a new set that only contains unique values, eliminating duplicate elements.

 

3-3. Dictionary Comprehensions

  • Filtering or transforming key-value pairs of an existing dictionary based on certain conditions to create a new dictionary concisely.
  • This is useful for improving efficiency in dictionary data processing tasks and enhancing code readability.
 
 
 

 

'Python(Eng. ver)' 카테고리의 다른 글

13. Scope of Variable in Python  (0) 2024.03.18
12. User-Defined Function  (0) 2024.03.15
10. Loop Statement in Python  (0) 2024.03.14
9. Conditional Statements in Python  (0) 2024.03.14
8. Operator in Python  (0) 2024.03.14