Advertisement
mikhailemv

Untitled

Oct 7th, 2022
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import csv
  2. import re
  3.  
  4. csv_file = input()
  5.  
  6. with open(csv_file, 'r', encoding='utf-8') as f:
  7.     reader = csv.reader(f)
  8.     title = next(reader)
  9.     data, title[0] = [], 'name'
  10.     html_tags = re.compile(r'<[^>]+>')
  11.     for line in reader:
  12.         if len(line) < len(title):
  13.             continue
  14.         is_correct_string = True
  15.         for index, value in enumerate(line):
  16.             normal_string = re.sub(html_tags, '', value)\
  17.                 .replace('\n', ', ')\
  18.                 .replace('\r\n', ', ')
  19.             normal_string = ' '.join(normal_string.split())
  20.             line[index] = normal_string
  21.             if len(normal_string) == 0:
  22.                 is_correct_string = False
  23.                 break
  24.         if is_correct_string:
  25.             current_dict = {title[i]: line[i] for i in range(len(title))}
  26.             for key in current_dict.keys():
  27.                 print(f'{key}: {current_dict[key]}')
  28.             print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement