Hi,
I need help creating nested lists
my code follows - test = ["a","b","c"]
-
testtwo = ["e","f","g"]
-
-
mo = []
-
for i in range (0,len(test)):
-
for j in range(0,len(testweb)):
-
moa = test[i]+testweb[j]
-
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
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: - >>> s = slice(10,20)
-
>>> s.indices(15)
-
(10, 15, 1)
-
>>> s.indices()
-
Traceback (most recent call last):
-
File "<interactive input>", line 1, in ?
-
TypeError: indices() takes exactly one argument (0 given)
-
>>>
You may want a dictionary with empty lists as values. - >>> test = ["a","b","c"]
-
>>> testtwo = ["e","f","g"]
-
>>> mo = {}
-
>>> for i in test:
-
... for j in testtwo:
-
... mo.setdefault(i+j, [])
-
...
-
[]
-
[]
-
[]
-
[]
-
[]
-
[]
-
[]
-
[]
-
[]
-
>>> mo
-
{'be': [], 'bf': [], 'bg': [], 'ae': [], 'ag': [], 'af': [], 'cg': [], 'cf': [], 'ce': []}
-
>>>
Hi,
Thanks for this info. I used the dict in Python and it worked.
Thanks again.
Rajasankar
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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. ...
|
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:...
|
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);
}
|
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...
|
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>...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |