can i write dictionary[key][list][3]
to mean the 3rd item in the list that is the corresponding value for 'key' ? 6 8430
ruari mactaggart wrote: can i writedictionary[key][list][3]
to mean the 3rd item in the list that is the corresponding value for 'key' ?
No, but you can write dictionary[key][2] for that purpose:
-- that[list] notation is unneeded and unsupported,
-- indices start from 0 so the 3rd one is indexed as [2]
Alex
ruari mactaggart wrote: can i write
dictionary[key][list][3]
to mean the 3rd item in the list that is the corresponding value for 'key' ?
You don't need the[list] part. Assuming you mean something like:
bands = {'beatles': ['john','paul','george','ringo']}
....then bands['beatles'][3] == 'ringo'
Peace,
Joe
what if i mean
bands={'beatles':['john','paul','george','ringo'],['guitar','bass','guitar',
'drums']}
then i need to put bands['beatles'][1][3]='percussion'
i presume... ?
Joe Francia <us****@soraia.com> wrote in message
news:Jn**********************@news.easynews.com... ruari mactaggart wrote: can i write
>dictionary[key][list][3] to mean the 3rd item in the list that is the corresponding value for
'key' ? You don't need the[list] part. Assuming you mean something like:
bands = {'beatles': ['john','paul','george','ringo']}
...then bands['beatles'][3] == 'ringo'
Peace, Joe
ruari mactaggart wrote: what if i mean
bands={'beatles':['john','paul','george','ringo'],['guitar','bass','guitar', 'drums']}
Invalid syntax.
then i need to put bands['beatles'][1][3]='percussion'
If you mean that bands is a dictionaries of tuples of lists, yes, but you
need parentheses around the tuples (and I would suggest some formatting
for greater readability), e.g.:
bands = {'beatles': ( ['john', 'paul', 'george', 'ringo'],
['guitar', 'bass', 'guitar', 'drums'] )
}
Alex
[ruari mactaggart] what if i mean bands={'beatles':['john','paul','george','ringo'],['guitar','bass','guitar', 'drums']}
then i need to put bands['beatles'][1][3]='percussion'
i presume... ?
No need to presume.
Just fire up the interpreter and see.
Compared to comp.lang.python responders,
the results are instant, always accurate, and
immediately available for exploring alternatives.
Raymond Hettinger
"ruari mactaggart" <ru***@charliefortune.com> wrote in message
news:bo**********@news7.svr.pol.co.uk... what if i mean
bands={'beatles':['john','paul','george','ringo'],['guitar','bass','guitar', 'drums']}
then i need to put bands['beatles'][1][3]='percussion'
i presume... ?
If things are getting this complicated, you're probably better off a)
wrapping an interface to this dict using an object, or b) just using object
attributes and using those objects as dictionary items.
Oh, and you need to group those two lists into a single list or tuple....
--
Francis Avila This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Narendra C. Tulpule |
last post by:
Hi,
if you know the Python internals, here is a newbie question for you.
If I have a list with 100 elements, each element being a long string,
is it more efficient to maintain it as a dictionary...
|
by: T. Earle |
last post by:
To list,
I'm trying to figure out the best approach to the following problem:
I have four variables:
1) headlines
2) times
3) states
4) zones
|
by: chad |
last post by:
I am writing a program to do some reliability calculations that
require several nested for-loops. However, I believe that as the
models become more complex, the number of required for-loops will...
|
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: David Pratt |
last post by:
Hi. I like working with lists of dictionaries since order is preserved
in a list when I want order and the dictionaries make it explicit what
I have got inside them. I find this combination very...
|
by: techiepundit |
last post by:
I'm parsing some data of the form:
OuterName1 InnerName1=5,InnerName2=7,InnerName3=34;
OuterName2 InnerNameX=43,InnerNameY=67,InnerName3=21;
OuterName3 ....
and so on....
These are fake...
|
by: Matthew Schibler |
last post by:
I'm a newbie to Python, with some experience using perl (where I used
nested arrays and hashes extensively). I am building a script in
python for a MUD I play, and I want to use the shelve module...
|
by: Brandon |
last post by:
Hi all,
I am not altogether experienced in Python, but I haven't been able to
find a good example of the syntax that I'm looking for in any tutorial
that I've seen. Hope somebody can point me...
|
by: cnb |
last post by:
Are dictionaries the same as hashtables?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |