473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Rookie Question: Passing a nested list into a function?

I am trying to pass the value of a nested list into a function (to my "if"
statement) as follows:

textfilelist = [["titlelist1[x][1]"]]
def idfer(listlength, comparelistlength, list):
while x < (listlength - 1):
while y < comparelistlength:
if list == titlelist2[y][1]:
(I cutoff the end to focus on the problem)

#Here i call my function hoping i am passing the value within
textfilelist[0][0] to my function
idfer(textfilelist[0][1], textfilelist[1][1], textfilelist[0][0])
--------------
I don't if there is a "legal" way to do this, but I would appreciate some
guidance.

Thanks,

Brett
Jul 19 '05 #1
4 1491

Do you really want quotation marks around "titlelist1[x][1]" ?

e.g.
textfilelist = [["titlelist1[x][1]"]]
textfilelist[0][1]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
IndexError: list index out of range

On Thursday 14 April 2005 06:51 pm, Brett wrote: I am trying to pass the value of a nested list into a function (to my "if"
statement) as follows:

textfilelist = [["titlelist1[x][1]"]]
def idfer(listlength, comparelistlength, list):
while x < (listlength - 1):
while y < comparelistlength:
if list == titlelist2[y][1]:
(I cutoff the end to focus on the problem)

#Here i call my function hoping i am passing the value within
textfilelist[0][0] to my function
idfer(textfilelist[0][1], textfilelist[1][1], textfilelist[0][0])
--------------
I don't if there is a "legal" way to do this, but I would appreciate some
guidance.

Thanks,

Brett


--
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Jul 19 '05 #2
I think so. I later reference it as textfilelist[0][0]. My intent is to be
able to use: titlelist1[x][1] as part of my "if" statement in my function.

-Brett

"James Stroud" <js*****@mbi.ucla.edu> wrote in message
news:ma**************************************@pyth on.org...

Do you really want quotation marks around "titlelist1[x][1]" ?

e.g.
textfilelist = [["titlelist1[x][1]"]]
textfilelist[0][1]

Traceback (most recent call last):
File "<stdin>", line 1, in ?
IndexError: list index out of range

On Thursday 14 April 2005 06:51 pm, Brett wrote:
I am trying to pass the value of a nested list into a function (to my
"if"
statement) as follows:

textfilelist = [["titlelist1[x][1]"]]
def idfer(listlength, comparelistlength, list):
while x < (listlength - 1):
while y < comparelistlength:
if list == titlelist2[y][1]:
(I cutoff the end to focus on the problem)

#Here i call my function hoping i am passing the value within
textfilelist[0][0] to my function
idfer(textfilelist[0][1], textfilelist[1][1], textfilelist[0][0])
--------------
I don't if there is a "legal" way to do this, but I would appreciate some
guidance.

Thanks,

Brett


--
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/

Jul 19 '05 #3
Brett,

Hard to tell exactly what you're trying to do here, but it looks like
you'd be better served using one of the built in python data
structures.

For example: If you're trying to compare some elements of these
textfiles that are broken into titles, and contents for each file, try
something like:

myfiles = [ 'test.txt', 'test1.txt', 'test2.txt', 'test3.txt',
'test4.txt' ]
myfiledict = {}

for filename in myfiles:
openfile = file(filename)
myfiledict[filename] = [ line.strip() for line in
openfile.readlines()]
openfile.close()
# easier to read this way
# self.content = []
# for line in f.readlines():
# self.content.append(line.strip())
# then the contents of the file "test.txt" are accessable with the
expression:
# myfiledict['test.txt']

# if you make a few lists of files, then you can compare them like this

for k1, k2 in myfiledict, cmpfiledict:
# if list == titlelist2[y][1]: From your code. The line below is
what
# I think you want.
if k1 == k2:
# Whatever happens in your code that you've clipped.

If you post the rest of your code, or email me, then I'll be happy to
answer your question.

-S

Jul 19 '05 #4
On Thu, 14 Apr 2005 20:51:08 -0500, "Brett" <bj***@yahoo.com> declaimed
the following in comp.lang.python:
I am trying to pass the value of a nested list into a function (to my "if"
statement) as follows:

textfilelist = [["titlelist1[x][1]"]]
This list consists of one element -- a character string
"titlelist1[x][1]"
def idfer(listlength, comparelistlength, list):
Don't use "list" as a variable, you are overriding a built-in
function.
while x < (listlength - 1):
Is there any chance you want a for loop rather than a while
loop? "x" does not have a value here, and nowhere do you assign it one.

for x in range(listlength): # range returns 0..arg-1
while y < comparelistlength:
for y in range(comparelistlength):
if list == titlelist2[y][1]:
And where is "titlelist2" defined (I cutoff the end to focus on the problem)

#Here i call my function hoping i am passing the value within
textfilelist[0][0] to my function
idfer(textfilelist[0][1], textfilelist[1][1], textfilelist[0][0])
There are no elements for [1] (in either position)

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Ted Lilley | last post by:
What I want to do is pre-load functions with arguments by iterating through a list like so: >>>class myclass: .... pass >>>def func(self, arg): .... print arg >>>mylist = >>>for item...
7
by: GS | last post by:
in VS .net vb 2005 express, I failed to find the option for leaving out warning in the Errors tab but still leave Warning in the warning tab listing. Can someone give me some hints? thank you...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.