Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Slices Slice Functions

Travis John Villanueva
Travis John Villanueva
5,052 Points

Desired output for this problem

Hi,

What is the required output for this task?

for example= my_array=(1,2,3,4,5,6,7,8,9,10)

desired outcome is equals to: 123478910

am i right?

slices.py
def first_4(raw):
    return raw[:4]


def first_and_last_4(raw):
    first_4=raw[:4]
    last_4=raw[len(raw)-4:]
    s= first_4 + last_4
    x="".join(map(str,s))
    return x

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Travis,

You've identified the right numbers to output, but not the correct data type. You should be preserving the data type of the input iterable, just like you've done in the first challenge. So if the challenge passed ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] (list of strings) into your function, you would pass back a list of strings, specifically, ['a', 'b', 'c', 'd', 'f', 'g', 'h', 'i']. Similarly, if your function was given a list of integers, such as [1, 2, 3, 4, 5, 6, 7, 9, 10], you should return a list of integers: [1, 2, 3, 4, 7, 8, 9, 10].

If your function received a tuple input (like you are describing with your 'my_array'), such as (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), the slice function will preserve that data type and will also produce a tuple, so the correct output in that case would be (1, 2, 3, 4, 7, 8, 9, 10).

Right now you are returning a string, regardless of the input.

Hope that points you in the right direction

Cheers

Alex