Python Forum
Replace based on values in a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Replace based on values in a file
#1
I have a file containing records with 4 values, eg:
1,Genesis,Gen,Gen
2,Eksodus,Eks,Exo
3,Levitikus,Lev,Lev
4,Numeri,Num,Num
5,Deuteronomium,Deut,Deu
6,Josua,Jos,Jos
7,Rigters,Rig,Jdg
8,Rut,Rut,Rth
9,1 Samuel,1 Sam,1Sa

I need to read these into an array and I then need to read a second file and in each record of this file replace occurrences of the 3rd field in the first file (Gen, Eks, Lev, Num, Deut etc.) with the first field (1,2,3, etc. followed by a fullstop, eg 1., 2., 3.).

So if the second has a record reading:

Ps. 19:3; Num 3:1........
This needs to be replaced by:
19.19:3; 4.3:1.....

How would I achieve this? I have just started learning Python, so I am really a novice.
Yoriz write Jan-30-2023, 06:14 AM:
Moved to homework:
https://python-forum.io/misc.php?action=help&hid=52 Wrote:Homework and No Effort Questions
This forum is focused on education. It exists to help people learn Python. We don’t exist to solve others' problems.
Reply


Messages In This Thread
Replace based on values in a file - by WJSwan - Jan-30-2023, 05:45 AM
RE: Replace based on values in a file - by WJSwan - Jan-30-2023, 09:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting data based on DataFrames values 577e94982d620b84f7c536d5e76f1e 0 2,076 Dec-03-2018, 02:23 AM
Last Post: 577e94982d620b84f7c536d5e76f1e
  file a table of values Ybivashka322 4 3,760 Dec-14-2017, 06:11 PM
Last Post: mpd
  logic comparater based on dictionary values ijosefson 3 3,283 Oct-16-2017, 06:04 AM
Last Post: Mekire

Forum Jump:

User Panel Messages

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