Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

removing a certain number from the output

I need help with this code

chapter_count_book_a = 3
verse_count_book_a = [2,2,2]


def get_book_data(book,chapter_count, verse_count):
    if chapter_count != len(verse_count):
       print("ERROR!!!")
    answer = []
    for chapter in range(0,chapter_count):
        chp = book + "." + str(chapter+1)
        next_verse = verse_count[chapter]
        for verse in range(0,next_verse):
            answer.append(chp+"."+str(verse+1))
    return answer
book_a_data = get_book_data("",chapter_count_book_a, verse_count_book_a)

print(book_a_data)

I have this code here, I try to remove it from every verse and chapter -7

I’m looking for this output if I have ['.1.1', '.1.2', '.2.1', '.2.2', '.3.1', '.3.2']

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want ['.-6.-6', '.-6.-5', '.-5.-6', '.-4.-4', '.-4.-6', '.-4.-5']
the number 10.10 should have an output of 3.3

How do I do that? I’m new to Python, so I’m going to need help from someone more advanced thanx

>Solution :

Maybe it’s not the more pythonic way but it works:

result=[]
for chapter in book_a_data:
    for number in chapter.split("."):
        if number.isdigit():
            chapter = chapter.replace(number, f"{int(number)-7}", 1)
    result.append(chapter)

print(result)

Result:

['.1.1', '.1.2', '.2.1', '.2.2', '.3.1', '.3.2']
['.-6.-6', '.-6.-5', '.-5.-6', '.-5.-5', '.-4.-6', '.-4.-5']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading