main thread

Suppose at some point in my code I have the following objects:

**A** = a single element from **lst**

**partial** = a list containing all subsets of **lst** (without **A** in them) of length **k-1**

I want to add **A** to each element in **partial**.

My question is: can I do so using list comprehension?

List comprehension uses for, therefore i suppose thats forbidden.

Why not use slicing? as it mention in the assignment it is allowed.

those restrictions were only stated for Q2. For Q3 there were no explicit restrictions, that's why I asked…

Yes, you can

(*no problem* using loops, lists comprehension or any other syntax in Q3, as long as the solution is recursive).

If you're stuck with the actual syntax, just treat every list in A as an "item" in the new list, and consider what is the function/operator you want to use on it.

So you are saying it is ok to combine a for and a recursion in the solution of this question?

May i use the function choose_sets as an envelop function to recursive function ?

במימוש של פונקציית choose_sets,

אני יכולה להשתמש בפונקציית עזר שאינה רקורסיבית?

Try not to. The idea here is to use recursion as the main control structure of the solution, in addition perhaps to a simple loop/list comprehension.

If you managed through this, you'll gain a better understanding of recursive design.

האם מותר להשתמש בפונקציית עזר שמטפלת רק בעניין הכפילות של התת רשימות? במידה ולא- אם הפונקצייה תמומש בצורה רקורסיבית זה בסדר?

There's no good reason for you to obtain duplicate sublists which you need to handle.

Try to come up with a recursive formulation which does not allow for duplications in the first place.

באחת מדוגמאות ההרצה שניתנו בשאלה, כאשר אורך הרשימה של הקלט היה שווה ל-k, הפלט שניתן היה אותה הרשימה רק בסדר הפוך.

יש חשיבות להחזיר את הרשימה בסדר הפוך?

שלום,

הצלחתי לבנות את הפונקציה המבוקשת, אך עבור קלטים גדולים ותתי רשימות בגודל קטן לוקח לה זמן לא סביר להוציא פלט (בסופו של דבר היא מבצעת את הנדרש).

האם יורד ניקוד על סיבוכיות?

Even a reasonable solution will take a long time to return on a big enough problem.

We did not specify a complexity bound for your solutions, but we may take off points on extremely ones. If you followed the hint we provided you should be fine.

Can we assume that the input list has items of the same type (e.g. a list of strings only, a list of integers only)?

what should be returned for "choose_sets([],0)"? should it be "[]" or "[[]]"?

I think it should be [[]], just like in the first example given in the homework sheet.

The list returned by the function is a list of the possible sub-sets. There's only one way to put together an empty sub-list from an empty list, and that possibility is the empty list ( [] ). Therefore, the list returned should be a list containing only an empty list.

Can you please verify for me that the following will always apply?

- len(lst) >= k
- int(k) == k
- 0 <= k