Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSc 1 2 0 : List to String ( Version 2 ) Expected Behavior Write a function concat _ elements ( slist , startpos, stoppos

CSc 120: List to String (Version 2)
Expected Behavior
Write a function concat_elements(slist, startpos, stoppos), where slist is a list of strings and startpos and stoppos are integers, that concatenates the elements of slist starting at position startpos and ending at position stoppos (inclusive) and returns the resulting string.
Your code should behave reasonably for all values of startpos and stoppos: if startpos is negative, concatenation should start with the first element of slist; if stoppos >= len(slist), concatenation should stop at the last element of slist. If startpos > stoppos it should return the empty string. See the examples below.
Programming Requirements
Solve this problem without explicitly iterating over the list. One way to do this involves a combination of slicing and join().
Examples
concat_elements(['aa','bb','cc','dd'],1,3)
return value: 'bbccdd'
concat_elements(['aa','bb','cc','dd'],-1,1)
return value: 'aabb'
concat_elements(['aa','bb','cc','dd'],-9,9)
return value: 'aabbccdd'
concat_elements(['aa','bb','cc','dd'],3,3)
return value: 'dd'
concat_elements(['aa','bb','cc','dd'],3,1)
return value: ''

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

=+Construct a data- and research-driven SWOT analysis

Answered: 1 week ago

Question

=+Who are our customers?

Answered: 1 week ago

Question

=+What are our goals presently?

Answered: 1 week ago