第5題 List Overlap(清單重疊) <<
Previous Next >> 解答-1
題目-1
Exercise 5
Take two lists, say for example these two:
and write a program that returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists of different sizes.
Extras:
- Randomly generate two lists to test this
- Write this in one line of Python (don’t worry if you can’t figure this out at this point - we’ll get to it soon)
List properties
In other words, “things you can do with lists.”
One of the interesting things you can do with lists in Python is figure out whether something is inside the list or not. For example:
You can of course use this in loops, conditionals, and any other programming constructs.
清單 5
拿兩個列表,舉例來說,這兩個:
並編寫一個程序,該程序返回一個列表,該列表僅包含列表之間的公共元素(無重複項)。確保您的程序可以在兩個不同大小的列表上運行。
附加功能:
- 隨機生成兩個列表進行測試
- 用Python的一行代碼編寫(不要擔心,如果您現在不能解決這個問題,我們會盡快處理)
列出屬性
換句話說,“您可以使用列表執行的操作”。
您可以使用Python中的列表進行有趣的操作之一,就是確定列表中是否包含某些內容。例如:
您當然可以在循環,條件和任何其他編程構造中使用它。
第5題 List Overlap(清單重疊) <<
Previous Next >> 解答-1