How do i create a list of paired items?

This is the place for queries that don't fit in any of the other categories.

How do i create a list of paired items?

Postby dogdaynoon » Sat Jun 15, 2013 5:28 am

I am not sure how to ask this question so i am having trouble googleing it. I will just put what i want to accomplish and maybe someone can point me to a tutorial or help me out. either way i am good. I like learning.

I want to create a list of pairs i guess: meaning

list = [ "this.txt" and "this.xfc",
"another.txt" and "another.xfc",
"yet_more.txt" and "yet_more.xfc"]

does that make sense?

what i am trying to do is walk through the file system and create a list of .txt files and the matching .xfc file with the same name but obviously a different extension.
I can walk the file system and pull each file type individually just fine but i would like to store them in a list together.
Last edited by Yoriz on Sun Jun 16, 2013 2:06 pm, edited 1 time in total.
Reason: edited the title
dogdaynoon
 
Posts: 12
Joined: Thu May 23, 2013 11:56 pm

Re: list pairs help

Postby micseydel » Sat Jun 15, 2013 7:36 am

Code: Select all
("this", "is", "a", "tuple")

If you're not aware of tuples, or for that matter that you can put lists in lists, then you should revisit a basic tutorial.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1271
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: list pairs help

Postby Yoriz » Sat Jun 15, 2013 10:01 am

A list of read only pairs (list of tuples)
Code: Select all
list = [("this.txt", "this.xfc"),
        ("another.txt", "another.xfc"),
        ("yet_more.txt", "yet_more.xfc")]

A list of changeable pairs (list of lists)
Code: Select all
list = [["this.txt", "this.xfc"],
        ["another.txt", "another.xfc"],
        ["yet_more.txt", "yet_more.xfc"]]


Just noticed
create a list of .txt files and the matching .xfc file with the same name but obviously a different extension

If both items have exacly the same name and only a differant extension rather then duplicate data, you only need a normal list with each name in it.
Step through the list and just add the required extension to it.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 783
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: How do i create a list of paired items?

Postby dogdaynoon » Mon Jun 17, 2013 3:38 pm

@ micseydel
Really helpful thanks.
I am constantly visiting basic tutorials and how to's. Programming doesn't come naturally to me much like skateboarding doesn't come natural to paraplegics. I struggle through and do what I can.
But yeah, still don't get your answer of "tuples"

@Yoriz
Thank you, I will use the list of names with no extensions approach. See what brainstorming can do miceydel. sometimes people can come up with better solutions than the one that was originally presented.

James
dogdaynoon
 
Posts: 12
Joined: Thu May 23, 2013 11:56 pm

Re: How do i create a list of paired items?

Postby micseydel » Mon Jun 17, 2013 3:43 pm

I guess when I mentioned tuples, I should have said that you can put them in lists.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1271
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: How do i create a list of paired items?

Postby dogdaynoon » Mon Jun 17, 2013 4:02 pm

thanks!
dogdaynoon
 
Posts: 12
Joined: Thu May 23, 2013 11:56 pm


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 4 guests