Answer to Question #312625 in Python for Chetan mirje

Question #312625

Given a list of different right and left foot shoes, write a python code to return the exact number of shoe pairs which can be formed from the given list. Also, return how many number of shoes of which foot are required to form pairs with the unpaired shoes.



Input Format



Input_list = ['R','L','L','R','R',R','R,'L']



Constraints



.



Output Format



Paired: 3



Unpaired: 2



Required left Shoes



Sample Input 0



8


L R L L R L R L


Sample Output 0



Paired: 3


Unpaired: 2


Required right shoes


Sample Input 1



9


R L R L R R L R R


Sample Output 1



Paired: 3


Unpaired: 3


Required left shoes


Sample Input 2



6


R R R R R R


Sample Output 2



Paired: 0


Unpaired: 6


Required left shoes


Sample Input 3



8


L L R L R R L R


Sample Output 3



Paired: 4


Unpaired: 0

1
Expert's answer
2022-03-17T13:56:07-0400
def paired_shoes(L):
    left = right = 0
    for shoe in L:
        if shoe == 'R':
            right += 1
        if shoe == 'L':
            left += 1

    paired = min(left, right)
    unpaired = max(left, right) - paired

    if left > right:
        shoes = 'left'
    elif right > left:
        shoes = 'right'
    else:
        shoes = None
    return paired, unpaired, shoes


def main():
    n = int(input())
    line = input()
    L = line.split()

    paired, unpaired, shoes = paired_shoes(L)

    print('Paired:', paired)
    print('Unpaired:', unpaired)
    if shoes is not None:
        print('Required', shoes, 'shoes')

main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS