简体   繁体   中英

Reg ex in python

I have a string accepted from the user movie="Jumanji"

I want to search this string in a csv file using the variable name irrespective of the case. My file is like:

movieId     title        genres

1          Jumanji(1995)   Adventure|children|fantasy

2          Friends(1994)   Romance|Comedy

After searching it should return the genre.

Load the file and search iteratively over each line:

with open('your_csv_file.csv', 'r') as infile:
    lines_with_movie_name = [line for line in infile if movie.lower() in line.lower()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM