Python | Read file | Search string | Accumulation/Count | readline() | lower() | split()

Aaron Lefler

Public

0

0 snippets
1"""
2- Python open() method to read csv file. 
3- Return and print the total times the word "love" appeared in the list.
4- Specifically, in the index position "Song Title".
5- Other methods used split(); readline(); lower(); print()
6- The **for** Loop definition - A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
7- Additionally, an accumulator or counter was used, by using a variable = 0. When "love", was found it would keep a running total.
8- "charts.csv" was provided and was 500 lines (501 including the header) of the Billboard Hot 100 list from October 2021.
9""" 
10
11file = open("charts.csv")      # open the file
12file.readline()
13total = 0
14love = "love"
15
16for line in file:
17    linelist = line.split(",")
18
19    loveIsDumb = linelist[2].lower()
20
21    if love in loveIsDumb:
22        total += 1
23
24print(total,"\n\nLooking for love in all the wrong places!\n")

No results

There are no results that match the criteria.

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
Legal
  • Security
  • Privacy Policy
  • Code Privacy
  • Terms of Service
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.