Advertisement
cityinspain

Album cipher program question

Mar 14th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. Hey #python,
  2.  
  3. I'm creating a tool to assist in creating book ciphers, or in this case, album ciphers. The user enters in the word they're looking for, and the program prints out the locations of the word's occurrences in the album. Right now it just prints "(the word) is found at position (position) in the file."
  4.  
  5. This is okay, but I want this tool to give me the title of the song it appears in and the position of the query relative to the beginning of the song, outputting something like, for example, "The word 'glitters' appears at position 8 in the song Stairway To Heaven", if the tool had been fed the full lyrics to the album Led Zeppelin IV. Obviously I could hardcode where to split songs, but I want to be able to reuse this and develop a tool to make the required text file for this to work, so it needs to be dynamic.
  6.  
  7. The way I decided to go about this was to have two data fields representing sections (songs) of the album: song name and the line it ends on. My first thought was to use JSON, but I'm struggling to figure out how to have JSON and regular text in the same file. I could make separate files, but that seems a bit unnecessarily complicated.
  8.  
  9. For now I've just used plaintext to signify the beginning of the section list, located at the end. Using Dark Side of the Moon as an example, I've determined the position of the last word of each song, and provided a header to tell Python where the section list starts and ends. Here is the example:
  10.  
  11. !BEGIN SECTIONS!
  12. Speak To Me:48
  13. Breathe (In The Air):153
  14. On The Run:161
  15. Time:343
  16. Breathe (Reprise):394
  17. The Great Gig In The Sky:433
  18. Money:652
  19. Us And Them:653
  20. Any Colour You Like:867
  21. Brain Damage:1055
  22. Eclipse:1173
  23. !END SECTIONS!
  24.  
  25. I'm sure I could just place this data at the top of the file and build the sections in the function I'm using to find the query, but I'd like to know if there's a better way to do this, purely to advance my own Python knowledge.
  26.  
  27. Thanks so much for reading :)
  28.  
  29. -cityinspain
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement