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

Join 118,659 Programmers for FREE! Ask your question and get quick answers from experts. There are 868 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



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


My Contributions


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


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


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 200



Thanked 2 times

Dream Kudos: 50
My Contributions


perl or python? Looks like python, I can't help you there.
User is offlineProfile CardPM

Go to the top of the page

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


New D.I.C Head

*
Joined: 3 Sep, 2007
Posts: 5


My Contributions


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

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


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,015



Thanked 2 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


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

Fast ReplyReply to this topicStart new topic
Time is now: 10/12/08 03:56AM

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