Python/파이썬 데이터 분석 스터디

DataCamp에서 파이썬 까리하게 쓰는 법 배움

Young_Metal 2022. 9. 29. 14:48
# Print the list created by using list comprehension
best_list = [name for name in names if len(name) >= 6]
print(____)

# Create a new list of odd numbers from 1 to 11 by unpacking a range object
nums_list2 = [*range(1,12,2)]
print(nums_list2)


# Rewrite the for loop to use enumerate
indexed_names = []
for i, name in enumerate(names):
    index_name = (i,name)
    indexed_names.append(index_name) 
print(indexed_names)

# Rewrite the above for loop using list comprehension
indexed_names_comp = [(i,name) for i,name in enumerate(names)]
print(indexed_names_comp)

# Unpack an enumerate object with a starting index of one
indexed_names_unpack = [*enumerate(names, 1)]
print(indexed_names_unpack)


# Use map to apply str.upper to each element in names
names_map  = map(str.upper, names)

# Print the type of the names_map
print(type(names_map))

# Unpack names_map into a list
names_uppercase = [*names_map]

# Print the list created above
print(names_uppercase)

'Python > 파이썬 데이터 분석 스터디' 카테고리의 다른 글

python Dataframe boolean  (0) 2022.09.21