Python Forum
How to solve this simple problem? Check if cvs first element is the same in each row?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to solve this simple problem? Check if cvs first element is the same in each row?
#1
Ok so I have a cvs with these information (I am using pipes and not commas):

1 | A | B
1 | C | D
2 | E | F


I need a code that does this:
If the first element of the row is the same as first element in the row above or below, then print that first element. I need this only for the first occurrence.

So in the case of 1 | A | B it should print "1" because it is the first occurrence in the cvs file. In case of the second row 1 | C | D it should do nothing because it's the second occurrence.

I don't know how to solve this. I know how to read the cvs file and get the elements.
Reply
#2
What should be the output of your test case?
Reply
#3
Pretty much the output I want is this:

<h1> 1 </h1>
<h2> A </h2>
B
<h2> C </h2>
D

<h1> 2 </h1>
<h2> D </h2>
E


So the first column is the H1 tag. However if there are more than 1 columns with the same info (for example "1" in our case) then just add the second and 3rd columns as h2 and content.
The most important thing is that there should no be two h1 tags with the same content.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can someone help me solve this programming problem? SuchUmami 6 833 Nov-20-2023, 10:01 AM
Last Post: EdwardMatthew
  list in dicitonary element problem jacksfrustration 3 625 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  A simple problem, how best to solve it? SuchUmami 2 683 Sep-01-2023, 05:36 AM
Last Post: Pedroski55
  How do I solve the second problem? Cranberry 1 1,092 May-16-2022, 11:56 AM
Last Post: Larz60+
  check if element is in a list in a dictionary value ambrozote 4 1,879 May-11-2022, 06:05 PM
Last Post: deanhystad
  Try to solve GTG multiplication table problem. Frankduc 6 1,937 Jan-18-2022, 08:26 PM
Last Post: Frankduc
  Sudoku Solver, please help to solve a problem. AdithyaR 5 2,044 Oct-28-2021, 03:15 PM
Last Post: deanhystad
Big Grin question about simple algorithm to my problem jamie_01 1 1,635 Oct-04-2021, 11:55 AM
Last Post: deanhystad
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,455 Aug-12-2021, 04:25 PM
Last Post: palladium
  Check common element in tuples PUP280 10 5,698 Nov-05-2020, 05:01 PM
Last Post: PUP280

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020