Goodafter noon all,

i would like some help on how to modify a python program to do the following:

1. Read both files actors.small.list and actresses.small.list and, using a dictionary, build a database that maps from each actor to a list of his or her films.

2. Two actors are “co-stars” if they have been in at least one movie together. Process the database/dictionary you built in the previous step and build a second database that maps from each actor to a list of his or her costars.

3. Have the user enter the name of a movie star (potentially repeatedly). Your program should print both the list of films the star appeared in and the list of all the co-stars.

import os
import re

def process_file(filename, f):
    """read the given filename and extract information;
    for each film, call f() with string arguments:
    actor, date, title, role """
    
    fp = open(filename)
    i = 0

    # skip over the header until you get to the following magic line
    for line in fp:
        if line.strip() == '----			------':
            break

    # regexp to recognize actor, tabs, movie
    split1 = re.compile('([^\t]*)\t*(.*)', re.UNICODE)

    # regexp to recognize title, date, role
    split2 = re.compile('([^\(]*)\s*(\([^\)]*\))[^\[]*(\[[^\]]*\])?', 
                        re.UNICODE)

    # regexp to recognize television (TV), video (V), video game (VG)
    video = re.compile('\(T?V|VG\)', re.U)

    actor = ''
    for line in fp:
        line = line.rstrip()
        if line == '': continue
        if line[0] == '-': break

        # split the line into actor info and movie info;
        # keep track of the current actor
        ro = split1.match(line)
        if ro:
            new_actor, info = ro.groups()
            if new_actor:
                actor = new_actor
        else:
            print 'BAD1', line
            continue

        # skip television shows (titles in quotation marks)
        if info[0] == '"':
            continue

        # skip made for TV and straight to video
        if video.search(info):
            continue

        # split the info into title, date and role
        ro = split2.match(info)
        if ro:
            title, date, role = ro.groups()
            if date == None:
                print 'BAD2', line
                continue

            f(actor, date, title, role)
            i += 1
        else:
            print 'BAD3', line
            continue

    stat = fp.close()


if __name__ == '__main__':

    def print_info(actor, date, title, role):
        print actor, date, title, role

    process_file('actors.short.list', print_info)

help would be appreciated as i am stuck on this for a very long time.

no one can help me in this ?
its very important please

What problem are you currently having?

i would like to know how to implement those 3 steps above in the program .. im having a great difficulty with it .. thanks for your time

thanks for the links
ive seen them before but i jsut cant get the idea of how to code them

Well have a look, make a few demo programs to get the feel, then incorporate them into your main program.

For the unknowing, this is another example of the "never-ending-questions-with-little-or-no-code" method to get other people to write the code for them. The method is to keep asking questions until someone is worn down enough to write the code for them, while they sit on the veranda in the shade. Let this thread die as it should.

thanks SgtMe im starting to get the hang of it
and for wooee its not "never-ending-questions-with-little-or-no-code" i just needed a little help on where to get started .. i do my own work .. yu didnt have to bitch about it :)

Sorry "woooee" but I'm taking his side. I never ever ever ever ever give out free homework help. However, I will give links to sites and tiny snippets of code to get them started. "M3M69" is relatively new here, so go easy on them :)

how am i supposed to create a dictionary with the stripped out list i have ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.