본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 59

반응형

Q>

If you have 50 different plug types, appliances wouldn't be available and would be very expensive.

(50 가지 플러그 유형이 있다면 어플라이언스를 사용할 수 없으며 매우 비쌉니다.)

But once an electric outlet becomes standardized, many companies can design appliances, and competition ensues, creating variety and better prices for consumers.

(그러나 전기 콘센트가 표준화되면 많은 기업들이 어플라이언스를 설계 할 수있게되고 경쟁이 일어나 소비자의 다양성과 가격이 향상됩니다.)
-- Bill Gates

 

You are given a non-empty list of integers (X).

(비어 있지 않은 정수 (X) 목록이 제공됩니다.)

For this task, you should return a list consisting of only the non-unique elements in this list.

(이 태스크의 경우이 목록에있는 고유하지 않은 요소로만 구성된 목록을 리턴해야합니다.)

To do so you will need to remove all unique elements (elements which are contained in a given list only once).

(이렇게하려면 모든 고유 요소 (주어진 목록에 한 번만 포함 된 요소)를 제거해야합니다.)

When solving this task, do not change the order of the list.

(이 작업을 해결할 때 목록의 순서를 변경하지 마십시오.)

Example: [1, 2, 3, 1, 3] 1 and 3 non-unique elements and result will be [1, 3, 1, 3].

(예 : [1, 2, 3, 1, 3] 1 및 3 개의 고유하지 않은 요소 및 결과는 [1, 3, 1, 3]입니다.)

 

Input: A list of integers.

        (정수 목록.)

 

Output: An iterable of integers.

           (정수의 반복 가능.)

 

Example:

checkio([1, 2, 3, 1, 3]) == [1, 3, 1, 3]
checkio([1, 2, 3, 4, 5]) == []
checkio([5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5]
checkio([10, 9, 10, 10, 9, 8]) == [10, 9, 10, 10, 9]

 

How it is used: This mission will help you to understand how to manipulate arrays, something that is the basis for solving more complex tasks.

(이 임무는보다 복잡한 작업을 해결하기위한 기초 인 배열을 조작하는 방법을 이해하는 데 도움이됩니다.)

The concept can be easily generalized for real world tasks.

(이 개념은 실제 작업을 위해 쉽게 일반화 할 수 있습니다.)

For example: if you need to clarify statistics by removing low frequency elements (noise).

(예 : 저주파수 요소 (노이즈)를 제거하여 통계를 명확히해야하는 경우.)

You can find out more about Python arrays in one of our articles featuring lists, tuples, array.array and numpy.array.

(Python 배열에 대한 자세한 내용은 lists, tuples, array.array 및 numpy.array가 포함 된 기사에서 찾을 수 있습니다.)

 

Precondition:
0 < len(data) < 1000

 

A>

#Your optional code here
#You can import some modules or create additional functions

def checkio(data: list) -> list:
    #Your code here
    #It's main function. Don't remove this function
    #It's used for auto-testing and must return a result for check.

    #replace this for solution
    # data에서 하나씩 가져와 a에 저장하고 data에서 a갯수를 세서 2개 이상인거 찾는다.
    return (a for a in data if data.count(a) > 1)

#Some hints
#You can use list.count(element) method for counting.
#Create new list with non-unique elements
#Loop over original list


if __name__ == "__main__":
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert list(checkio([1, 2, 3, 1, 3])) == [1, 3, 1, 3], "1st example"
    assert list(checkio([1, 2, 3, 4, 5])) == [], "2nd example"
    assert list(checkio([5, 5, 5, 5, 5])) == [5, 5, 5, 5, 5], "3rd example"
    assert list(checkio([10, 9, 10, 10, 9, 8])) == [10, 9, 10, 10, 9], "4th example"
    print("It is all good. Let's check it now")

 

O>

It is all good. Let's check it now

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 61  (0) 2019.06.12
Python Learn the basics Quiz 60  (0) 2019.06.12
Python Learn the basics Quiz 58  (0) 2019.06.12
Python Learn the basics Quiz 57  (0) 2019.06.12
Python Learn the basics Quiz 56  (0) 2019.06.12