How to return list of lists

Eternaltheft eternaltheft at gmail.com
Thu Apr 25 11:41:55 EDT 2013


On Thursday, April 25, 2013 11:29:31 PM UTC+8, Wolfgang Maier wrote:
> <eternaltheft <at> gmail.com> writes:
> 
> 
> 
> > 
> 
> > Hi guys, I'm having a lot of trouble with this.
> 
> > 
> 
> > My understanding of python is very basic and I was wondering how I can
> 
> return this table as a list of lists.
> 
> > 
> 
> > 1	2	3	4	5
> 
> > 3	4	5	6
> 
> > 5	6	7
> 
> > 7	8
> 
> > 9
> 
> > 
> 
> > The function is 
> 
> > def Table(n): 
> 
> > Then how would I make it that when the value of n is 4 it returns [[1, 2,
> 
> 3], [3, 4], [5]].
> 
> > 
> 
> > Thank you 
> 
> > 
> 
> 
> 
> First of all, state your question precisely!
> 
> I have no idea why with n=4 you would want to return that!
> 
> Second, the solution of this sort of problem lies in list comprehensions
> 
> combined with range(). Read up on those topics! Especially comprehensions
> 
> are so fundamental to the language that you have know about them before you
> 
> embark on any serious programming efforts.
> 
> Best,
> 
> Wolfgang

Ah sorry the task is to make a function for this:
def tTable(n): 
tTable(n),even n, returns the initial triangular n-1 x n-1(triangular table i posted before) table as a list of lists. For example, tTable(4) returns [[1, 2, 3], [3, 4], [5]].

Sorry if i was a bit vague, but i don't know how to explain it any better :(. And thanks for the tips! I will definitely read up on it when i get the time. 



More information about the Python-list mailing list