myfile.csv
student_id,student_name,percentage 1,Ram,50 2,Jim,60 3,Jack,70 4,Jones,80 5,Rahim,90Code
with open("myfile.csv", mode = 'r') as f: data = f.read() print(data) print(type(data)) # <class 'str'> data = data.splitlines() # Splits the string at line breaks and returns a list print("List of strings") print(data) print(type(data)) # <class 'list'> # Using list comprehension # data = [x.split(',') for x in data] output = [] for i in data: output.append(i.split(",")) print("List of list") print(output)
Pages
- Index of Lessons in Technology
- Index of Book Summaries
- Index of Book Lists And Downloads
- Index For Job Interviews Preparation
- Index of "Algorithms: Design and Analysis"
- Python Course (Index)
- Data Analytics Course (Index)
- Index of Machine Learning
- Postings Index
- Index of BITS WILP Exam Papers and Content
- Lessons in Investing
- Index of Math Lessons
- Downloads
- Index of Management Lessons
- Book Requests
- Index of English Lessons
- Index of Medicines
- Index of Quizzes (Educational)
Friday, April 21, 2023
Demo of splitlines and split (Problem on Strings)
Labels:
Python,
Technology
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment