Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

A function that takes an interger and returns set of sets.

$
0
0
I need a function rep(n) that takes an integer and returns set of sets representing n. It must behave this way:
>>> rep(0)
[]
>>> rep(1)
[[]]
>>> rep(2)
[[], [[]]]
>>> rep(3)
[[], [[]], [[], [[]]]]
Python is new to me, so I am struggling a lot with the syntax. I am not sure how to write this function.
This is what I makes sense to me but I am sure this is nowhere near python code"
def rep(n):
[x for x in range(n)]
0 = []
1 = [[]]
for i in range(n)
return '[]' if i==0 else '[[]]' if n==1 else range(i)


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>