Menu

1 / 2

Weekly Challenge: Joining and splitting lists

DEV Community·Simon Green·6 months ago
#PDniwGdS
#task#my#examples#python#list
Reading 0:00
15s threshold

Weekly Challenge 373

Each week Mohammad S. Anwar sends out The Weekly Challenge , a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding.

Challenge , My solutions

Task 1: Equal List

Task

You are given two arrays of strings.

Write a script to return true if the two given array represent the same strings otherwise false.

My solution

For input from the command line, I take a string with items concatenated by commas to generate the two lists. This seems to the easiest way to handle this, allowing for empty items as per the fourth example.

def main (): result = equal_list ( sys . argv [ 1 ]. split ( " , " ), sys . argv [ 2 ]. split ( " , " )) print ( " true " if result else " false " )

Enter fullscreen mode

Exit fullscreen mode

This function is a one liner.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.