Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,251 Programmers. There are 2,126 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

how to print the rows of matrix on separate lines

 
Reply to this topicStart new topic

how to print the rows of matrix on separate lines

FarmGirl
post 26 Apr, 2008 - 05:36 PM
Post #1


New D.I.C Head

*
Joined: 3 Sep, 2007
Posts: 5



I have a 3 dimensional array

board = [[0,1,2],[3,4,5],[6,7,8]]

after running through a for loop, I want to return the newly changed board. Is there a way that I can return each row on a separate line so that it looks like this:

[0,1,2]
[3,4,5]
[6,7,8]

I have tried returning board[0]; board[1]; board[2]
but it only gives me board[0]

User is offlineProfile CardPM
Go to the top of the page
+Quote Post


KevinADC
post 26 Apr, 2008 - 05:51 PM
Post #2


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 168

perl or python? Looks like python, I can't help you there.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

FarmGirl
post 26 Apr, 2008 - 07:54 PM
Post #3


New D.I.C Head

*
Joined: 3 Sep, 2007
Posts: 5

QUOTE(KevinADC @ 26 Apr, 2008 - 05:51 PM) *

perl or python? Looks like python, I can't help you there.




Sorry I forgot to mention that it's python
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Nova Dragoon
post 28 Apr, 2008 - 10:47 AM
Post #4


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 5,754

The return statement in a function allows you to only pass one piece of data back to the caller, which will be the result of the expression in which the function was called

if I have this:
CODE

def function(a,b):
    c =  a+b
    d =  a* b
    e = a/b
    return a: b :c

def main():
    z = function(1/2)


What would z equal if I were able return all three of those values?


You should return the whole modified board, and in the caller extract the data you want.


you could also unpack the values as they come out of the function

CODE

def main():
   row0, row1,row2 = forLoopFunction(board)

User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 09:02AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month