Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:46:13+00:00 2026-06-03T12:46:13+00:00

So, this is the script that has very kindly been given to me as

  • 0

So, this is the script that has very kindly been given to me as a starter:

#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import with_statement    # needed for Python 2.5
from itertools import chain

def chunk(s):
    """Split a string on whitespace or hyphens"""
    return chain(*(c.split("-") for c in s.split()))

def process(latin, gloss, trans):
    chunks = zip(chunk(latin), chunk(gloss))
    # now you have to DO SOMETHING with the chunks!

def main():
    with open("examples.txt") as inf:
        try:
            while True:
                latin = inf.next().strip()
                gloss = inf.next().strip()
                trans = inf.next().strip()
                process(latin, gloss, trans)
                inf.next()    # skip blank line
        except StopIteration:
            # reached end of file
            pass

if __name__=="__main__":
    main()

However,

I’ve just spoken to my lecturer, who has let me know that he doesn’t want us using the

__ x __ 

function, as it is "too advanced for the students’ needs at this point in the course".
I’m absolutely stumped as to what I need to put into the "chunks" or "process" fields, up until now I’ve been able to figure most of the other exercises out (with a few hints) but this one is just way beyond me. This particular part is worth 15 points out of 20, and it’s making me feel just a little bit sick!
Any further help would be greatly appreciated.


Original post (sorry it’s so long!)

I’m trying to do the following: I have a text with a language other than english, broken up into morphemes (parts of each word) using hyphens, with the English gloss (linguistic translation of each morpheme) and a direct translation below. eg.

Itali-am fat-o profug-us Lavini-a-que ven-it

Italy-Fem:Sg:Acc fate-Neut:Sg:Abl fleeing-Masc:Sg:Nom Lavinian-Neut:Pl:Acc come:Perf-3-Sg:Indic:Act

‘in flight [driven] by fate came to Italy and the Lavinian [shores]’

I’ll have several texts such as the above in one file – i.e.

blank line

a line of latin broken up with hyphens

a line of gloss broken up with corresponding hyphens, using colons to join elements

a line of translation

blank line

latin

gloss

translation

ad infinitum.

What I need to do is write a file that gives me the following output:

Itali:    1    Italy
am:    1    Fem:Sg:Acc
fat:    1    fate
o:    1    Neut:Sg:Abl
profug:   1    fleeing
us:    1    Masc:Sg:Nom
Lavini:    1    Lavinian
a:    1    Neug:Pl:Acc
que:    1    come:Perf
ven:    1   3
it:     1   Sg:Indic:Act

where the first column represents the first line of text without hyphens; the second column indicates the number of occurrences (it’s only 1 each in this example), and the third column is the English translation of the first column, as written in the text.

If there’s a latin morpheme with no corresponding English gloss/translation, the Latin column will be as normal but the English column will print [unknown], like:

a:  1   [unknown]

And if the opposite, i.e. an English morpheme with no corresponding Latin, it should print

[unknown]:  1   kitten

Finally, the prog needs to be able to deal with homophonous morphemes (i.e. two identically spelled latin morphemes with different meanings). e.g.

a:  16  Neuter:Plural
a:  28  Feminine:Singular
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:46:14+00:00Added an answer on June 3, 2026 at 12:46 pm

    Whenever you need to count occurrences, you need a dictonary.

    Create a dictionary where the key is the tuple generated by zip, and the value is a list that has: [latin, amount, translation]. Each time you encounter the same tuple you increment the amount.

    The dictionary has to outlive the function so you probably want to add it as a parameter.

    Once you are done, you can do: result = dict.keys(); result.sort().

    I’m not sure I understand the part of the unknowns. If this does not solve that part, you might need to show a relevant example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the script that has very kindly been given to me as a
I have a bash script that has this function in it: function start_vi() {
I have this script that collects data from users and I want to check
I have a Python script that is running a few ls commands. This script
I'm trying to write a python script that packages our software. This script needs
I've been working on a very simple Jquery script that displays a few mini-dashboards
I do not think that this has been posted before - as this is
Well basically I have this script that takes a long time to execute and
I have this script that works, but I need to change the format of
I have a JS script that changes content of webpages. I use this script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.