This one might be a challenge...

Okay some of you might have an inkling what i'm trying to do already from the last thread (thanks for helping!) but I figured I should start a new topic for a new problem so that people can search solutions easier.

I've got multiple lists.

List 1 contains module names (LUBS5200M01, LUBS5250M01, COMP5500M01)
List 2 contains start times (1000, 1400, 1530)
List 3 contains end times (1200, 1600, 1600)

I need to create new files (the lists are all the same length, so maybe a "for i in range(len(list1))" sort of thing would work?) which have each row in a specific place. These new files will be .csv files and should have the filename "output_(x)" where "x" is a number, could just be sequential it doesn't really matter as long as it's unique.

They all have to be in separate files because it's calendar data, so i'm slowly building up .csv files separate event in. I'll later be adding the rest of the data, but below is an example:

##The finished .csv file should contain:
Subject, Start date, Start time, End date, End time, All day event, Description, Location, Private
##The .csv file i'm hoping to build now will contain:
LUBS5200M01, null, 1000, null, 1200, null, FALSE, null, null, FALSE
6 Years
Discussion Span
Last Post by Xzarik

Like this mate:

list1 = ['a', 'b', 'c']

for i in range(len(list1)):
    open('file%s.txt' % i, 'w').write(list1[i])

Cheers and Happy coding


Thanks for that, works well for the list of module names but i'm having trouble getting the other ones into the files. I know why - because i'm using the following code:

for i in range(len(actual_end_str)):
    for item in reference_list:
        if item[0] == actual_end_str[i]:   
            print item[1]

If i'm right it means that it's just going to print the second value from the "reference_list" (the end times) as individual items? I want to put these all in another list so that I can do that above file-writing thinger, but if I try and write "item[1]" to a new list it just does the last "item" which... well I sorta expected because it'll process it all in that way and once it's got all the "items" THEN it'll put the last known value into the list.

TLDR - I need to put all these into yet another list!


Oh sorry I seem to be solving my own problems straight after posting!

I changed the print function at the end to:


(After creating a list called "closer"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.