시작하기무료로 시작하기

Split lines or split the line?

You are about to leave work when a colleague asks you to use your string manipulation skills to help him. You need to read strings from a file in a way that if the file contains strings on different lines, they are stored as separate elements. He also wants you to break the strings into pieces if you see that they contain commas.

The text of the file has been already saved in the variable file. You can use print(file) to view the variable in the IPython Shell.

이 연습은 강의의 일부입니다

Regular Expressions in Python

강의 보기

연습 안내

  • Split the string file into many substrings at line boundaries.
  • Print out the resulting variable file_split.
  • Complete the for-loop to split the strings into many substrings using commas as a separator element.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Split string at line boundaries
file_split = ____

# Print file_split
print(____)

# Complete for-loop to split by commas
for ____ in ____:
    substring_split = substring.____
    print(substring_split)
코드 편집 및 실행