I have a list
x = [0] * 2
x = x * [2]
x[1,1] = 7
This gives me the x value
[[0,0] [0,0] [0,0] [0,7]]
I want to get the indices of the value 7.
i.e. something like
i = a.index(max(a)) gives me '1'
This only gives me the index in one dimension. Is there any method by
which I can get (1,1) as the answer.
Thanks in advance. 3 1188 sr********@gmail.com wrote: I have a list
x = [0] * 2 x = x * [2]
You're certainly not doing that. x = [0] * 2 x = x * [2]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: can't multiply sequence by non-int
And even if you *do* do what it looks like you think you want to do x = [[0] * 2] * 2 x
[[0, 0], [0, 0]]
...you don't get what you think you'd get..
So, let's say you do this x[1][1] = 7 x
[[0, 7], [0, 7], [0, 7], [0, 7]]
... still not what you thought
x = [[0] * 2] * 4 x
[[0, 0], [0, 0], [0, 0], [0, 0]]
x[1,1] = 7
This gives me the x value [[0,0] [0,0] [0,0] [0,7]]
I want to get the indices of the value 7. i.e. something like i = a.index(max(a)) gives me '1'
This only gives me the index in one dimension. Is there any method by which I can get (1,1) as the answer.
When you sort out what you're actually trying to do, the answer to your
question may be in this thread: http://groups.google.ca/group/comp.l...925504b2a4eb4a Thanks in advance.
Hope this helps,
~Simon sr********@gmail.com wrote: I have a list
x = [0] * 2 x = x * [2] x[1,1] = 7
This gives me the x value [[0,0] [0,0] [0,0] [0,7]]
I want to get the indices of the value 7. i.e. something like i = a.index(max(a)) gives me '1'
This only gives me the index in one dimension. Is there any method by which I can get (1,1) as the answer.
Thanks in advance.
If you post code that doesn't work, people won't treat you seriously.
I have some code that might help if you'd like to try again.
All the best
Gerard
Gerard Flanagan wrote: sr********@gmail.com wrote: I have a list
x = [0] * 2 x = x * [2] x[1,1] = 7
This gives me the x value [[0,0] [0,0] [0,0] [0,7]]
I want to get the indices of the value 7. i.e. something like i = a.index(max(a)) gives me '1'
This only gives me the index in one dimension. Is there any method by which I can get (1,1) as the answer.
Thanks in advance.
If you post code that doesn't work, people won't treat you seriously. I have some code that might help if you'd like to try again.
All the best
Ok, that was mean-spirited. The code is below - it's related to
another problem but maybe it can be adapted to your own. Good luck!
def irows(n):
i=0
while True:
yield divmod(i,n)
i += 1
x = [0,0,0,7,0,0,0,0]
d = dict(zip(enumerate(x), irows(2)))
assert d[x.index(7),7] == (1,1)
assert d[x.index(0),0] == (0,0)
d = dict(zip(irows(2),x))
assert d[1,1] == 7
sudoku = dict(zip(irows(9),[[0]]*81)) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dan |
last post by:
I was recently surprised, and quite shocked in fact, to find that
Python treats negative indices into sequence types as if they were
mod(length-of-sequence), at least up to -len(seq).
This fact...
|
by: SnuSnu |
last post by:
Okay - here's a (probably) really easy question:
I can't do the following, so what's the best way to handle this
case of wanting to delete within a loop?
x =
deletion_list =
for i in...
|
by: andrea.gavana |
last post by:
Hello NG,
I was wondering if there is a faster/nicer method (than a for loop)
that will allow me to find the elements (AND their indices) in a list that
verify a certain condition. For example,...
|
by: Steven Bethard |
last post by:
I have a list of strings that looks something like:
lst =
The parentheses in the labels indicate where an "annotation" starts and
ends. So for example, the label '(*)' at index 2 of the list...
|
by: Ross MacGregor |
last post by:
I have a very simple yet complicated problem. I want to generate a
random list of indices (int's) for a container.
Let's say I have a container with 10 items and I want a list of 3 random...
| |
by: spam.noam |
last post by:
Hello,
I discovered that I needed a small change to the Python grammar. I
would like to hear what you think about it.
In two lines:
Currently, the expression "x" is a syntax error.
I suggest...
|
by: Girish Sahani |
last post by:
Hi,
Please check out the following loop,here indexList1 and indexList2 are a
list of numbers.
for index1 in indexList1:
for index2 in indexList2:
if ti1 == ti2 and not index1 !=...
|
by: GB |
last post by:
Hello,
I have a recursion function which generate 1-dimensional vector of integers
so for 3 cycles I have, for example, following vectors:
int vec1 = {1,3,2,4};
int vec2 = {2,5,6,2};
int vec3 =...
|
by: ck9663 |
last post by:
Hi guys.
I have a two-dimensional list. I need to see if a value is existing on the third column of each row. Just like searching a table with the third column as the index key.
Do you read...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |