Okay i'm really sorry to have basically bombarded this forum but this is my last cry for help on this project I swear!

I guess many of you are intimately familiar with what's happening so far, and thank you all so much for putting up with me =)

I've got three lists... (whoop, lists again)

List 1 - relevant_weeks - [['[11', " '05/10/2009'", " '06/10/2009'", " '07/10/2009'", " '08/10/2009'", " '09/10/2009']", ''], ['[10', " '28/09/2009'", " '29/09/2009'", " '30/09/2009'", " '01/10/2009'", " '02/10/2009']", ''], ['[27', " '25/01/2010'", " '26/01/2010'", " '27/01/2010'", " '28/01/2010'", " '29/01/2010']", '']]

List 2 - relevant_days - ['TUES', 'TUES', 'THURS', 'WED', 'THURS', 'MON', 'WED', 'THURS', 'WED', 'TUES', 'MON', 'WED', 'MON', 'WED', 'THURS', 'FRI', 'THURS']

List 3 - days_reference - [['0', ' MON', ' TUES', ' WED', ' THURS', ' FRI']]

What I need to do is take take the first value from list 1 (in this case it is: [11', " '05/10/2009'", " '06/10/2009'", " '07/10/2009'", " '08/10/2009'", " '09/10/2009']) and take the matching value from list 2 (so the first value in list 2 is: 'TUES').

Then I need to recognise that it says "TUES" and look up the position of the string "TUES" in list 3, take that position number and print the corresponding value from list 1 (So it would print "06/10/2009")

With a lot of time and stress I feel I could probably make it do that for one value, but for the life of me I wouldn't be able to do it for an entire list! (And... list 1 is a list of lists right?)

relevant_weeks = [['[11', " '05/10/2009'", " '06/10/2009'", " '07/10/2009'", " '08/10/2009'", " '09/10/2009']", ''],
                  ['[10', " '28/09/2009'", " '29/09/2009'", " '30/09/2009'", " '01/10/2009'", " '02/10/2009']", ''],
                  ['[27', " '25/01/2010'", " '26/01/2010'", " '27/01/2010'", " '28/01/2010'", " '29/01/2010']", '']]

relevant_days = ['TUES', 'TUES', 'THURS', 'WED', 'THURS', 'MON', 'WED', 'THURS', 'WED', 'TUES', 'MON', 'WED', 'MON', 'WED', 'THURS', 'FRI', 'THURS']

days_reference = [['0', ' MON', ' TUES', ' WED', ' THURS', ' FRI']]

days_reference = [item.strip() for item in days_reference[0]] # cleaning the list


for i in range(len(relevant_weeks)):
    print relevant_weeks[i][days_reference.index(relevant_days[i])]

Cheers and Happy coding

Difficult to see for what you are after with such scrambled data, but maybe something like this?

relevant_weeks = [['[11', " '05/10/2009'", " '06/10/2009'", " '07/10/2009'", " '08/10/2009'", " '09/10/2009']", ''],
                  ['[10', " '28/09/2009'", " '29/09/2009'", " '30/09/2009'", " '01/10/2009'", " '02/10/2009']", ''],
                  ['[27', " '25/01/2010'", " '26/01/2010'", " '27/01/2010'", " '28/01/2010'", " '29/01/2010']", '']]

relevant_days = ['TUES', 'TUES', 'THURS', 'WED', 'THURS', 'MON', 'WED', 'THURS', 'WED', 'TUES', 'MON', 'WED', 'MON', 'WED', 'THURS', 'FRI', 'THURS']

days_reference = [['0', ' MON', ' TUES', ' WED', ' THURS', ' FRI']]
days_reference = [[value.strip() for value in ref] for ref in days_reference]
print days_reference

relevant_weeks = eval(''.join([','.join(week) for week in relevant_weeks])) ## preparing real list of lists
relevant_weeks = [[int(week[0])] + (week[1:]) for week in relevant_weeks] ## change the number to integer value

print relevant_weeks
relevant_indexes = [ days_reference[0].index(day) for day in relevant_days ] ## indexes in sublists
print relevant_indexes

print "Index from integer value to relevant weekday indes to produce the day"
for week in relevant_weeks:
    weekno = week[0]
    print weekno
    if weekno > len(relevant_days):
        print 'No data for week',weekno
    else:
        print "%s of week %i" % (relevant_days[weekno], weekno)
        print week[relevant_indexes[weekno]]

Edited 6 Years Ago by pyTony: n/a

This question has already been answered. Start a new discussion instead.