| | |
Problem with nested list
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 8
Reputation:
Solved Threads: 0
Hi,
I am having the problem in nested list.
Here is the code :
Basically I am trying to insert the value for Met by in [ 'Met by', metlist->value]
I am getting list index out of range error.
Can any one help me out.
Thanks
I am having the problem in nested list.
Here is the code :
python Syntax (Toggle Plain Text)
data1= [['Contacts',company.contacts.count() ], ['Notes', company.notes.count()], ['Met by', ], ['Industry', industry], ['Financial Investors', '31']] for item in metlist: data1[2].insert(1,item)
I am getting list index out of range error.
Can any one help me out.
Thanks
Last edited by vegaseat; Oct 12th, 2008 at 11:21 am. Reason: added code tags [code=python] ... [/code]
•
•
•
•
I think what you're trying to do is:
for item in metlist:
data1[2].append(item)
To see what you did won't work, try typing data1[2]. It gives you ['Met by']..thus there is only one element, and nothing at position 1.
python Syntax (Toggle Plain Text)
>>> d = ['a'] >>> d.insert(1,'b') >>> d ['a', 'b']
Something like this might do ...
python Syntax (Toggle Plain Text)
# converted certain variables to strings for testing only data1= [['Contacts', 'company.contacts.count()'], ['Notes', 'company.notes.count()'], ['Met by', ], ['Industry', 'industry'], ['Financial Investors', '31']] data2 = [] for item in data1: #print item, len(item) # for testing if len(item) < 2: item.insert(1, 'missing value') data2.append(item) print data2 """ my output --> [['Contacts', 'company.contacts.count()'], ['Notes', 'company.notes.count()'], ['Met by', 'missing value'], ['Industry', 'industry'], ['Financial Investors', '31']] """
Last edited by vegaseat; Oct 12th, 2008 at 11:34 am.
May 'the Google' be with you!
![]() |
Similar Threads
- Random Number Problem For Lottery Program (Visual Basic 4 / 5 / 6)
- Anchoring problem in Firefox, it crops my browser after clicking the link (HTML and CSS)
- Searching within a nested list (Python)
- C++ counting problem (C++)
- How to implement heap in lisp? (Legacy and Other Languages)
- Problem while using two dimesional vector as a parameter to a method (C++)
- Drop Down Menu - Problem Opening in IE (JavaScript / DHTML / AJAX)
- query: allocating memory to nested linked lists (C)
- Giving records in MS Access unique numbers (MS Access and FileMaker Pro)
Other Threads in the Python Forum
- Previous Thread: Launching Python Scripts from within Scripts. Global names not defined.
- Next Thread: Effiency in list searching
Views: 671 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
ansi application array beginner c++ c/c++ change character class client code color command convert count create csv ctypes database dictionary django dll error examples excel exe extension extensions fdlib file float format framework ftp function graphics gui homework image images import input library line linux list lists logging loop loops microcontroller mouse mysql mysqldb number numbers output parse parsing path port prime processing program programming py2exe pygame pygtk pyqt python random raw_input recursion recursive redirect remote scrolledtext server socket ssh stdout string strings syntax table terminal text thread threading tkinter transparency tuple tutorial ubuntu unicode variable variables web windows wxpython






