473,396 Members | 2,052 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,396 software developers and data experts.

Help with nested list

Hi,

I need help creating nested lists

my code follows

Expand|Select|Wrap|Line Numbers
  1. test = ["a","b","c"]
  2. testtwo = ["e","f","g"]
  3.  
  4. mo = []
  5. for i in range (0,len(test)):
  6.     for j in range(0,len(testweb)):
  7.          moa = test[i]+testweb[j]
  8.          mo.append[moa]
I want final output like this

mo[ae[],af[],ag[],be[], ....... cg[]] instead of mo[ae,af,ag,be, ....... cg]

How to get this??? I've searched in this forum and couldn't find an answer.

Thanks,
Rajasankar
Jul 2 '09 #1
2 3957
bvdet
2,851 Expert Mod 2GB
Your desired output is invalid. The brackets '[]' represent a slice object. What you are wanting is similar to:
Expand|Select|Wrap|Line Numbers
  1. >>> s = slice(10,20)
  2. >>> s.indices(15)
  3. (10, 15, 1)
  4. >>> s.indices()
  5. Traceback (most recent call last):
  6.   File "<interactive input>", line 1, in ?
  7. TypeError: indices() takes exactly one argument (0 given)
  8. >>> 
You may want a dictionary with empty lists as values.

Expand|Select|Wrap|Line Numbers
  1. >>> test = ["a","b","c"]
  2. >>> testtwo = ["e","f","g"]
  3. >>> mo = {}
  4. >>> for i in test:
  5. ...     for j in testtwo:
  6. ...         mo.setdefault(i+j, [])
  7. ...         
  8. []
  9. []
  10. []
  11. []
  12. []
  13. []
  14. []
  15. []
  16. []
  17. >>> mo
  18. {'be': [], 'bf': [], 'bg': [], 'ae': [], 'ag': [], 'af': [], 'cg': [], 'cf': [], 'ce': []}
  19. >>> 
Jul 2 '09 #2
Hi,

Thanks for this info. I used the dict in Python and it worked.

Thanks again.


Rajasankar
Jul 3 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joel Forrest Moxley | last post by:
Greetings python-list! The good news is that I've been having a blast with Python since early Spring. I've had great success in both learning the language from online / usegroup resources and...
1
by: Joel | last post by:
python-list@python.org at Sun, 24 Aug 2003 13:31:58 but didn't seem to show up here] Greetings python-list! The good news is that I've been having a blast with Python since early Spring. ...
6
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote:...
15
by: Xah Lee | last post by:
Here's the belated Java solution. import java.util.List; import java.util.ArrayList; import java.lang.Math; class math { public static List range(double n) { return range(1,n,1); }
8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
1
by: Todd | last post by:
OK, I created a .htm page within a new Web solution: -------------------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head>...
8
by: rh0dium | last post by:
Hi all, I am using python to drive another tool using pexpect. The values which I get back I would like to automatically put into a list if there is more than one return value. They provide me...
37
by: Tim N. van der Leeuw | last post by:
Hi, The following might be documented somewhere, but it hit me unexpectedly and I couldn't exactly find this in the manual either. Problem is, that I cannot use augmented assignment operators...
6
by: deko | last post by:
How do I construct an XHTML-compliant nested unordered list? This displays correctly (both FF and IE): <ul> <li>list item</li> <li>list item</li> <li>list item</li> <ul> <li>nested list...
7
by: patrick j | last post by:
Hi I'm wondering about lists with nested lists as one does on a Saturday afternoon. Anyway below is an example of a list with a nested list which the iCab browser's very useful HTML...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.