Skip to content

S1Q2 · Join Even Index Strings

⚡ Quick Reference

Function: join_even_index_strings(words: list) -> str

Core idea: Concatenate the elements at index 0 and index 2.

def join_even_index_strings(words):
    return words[0] + words[2]

Key rules: - Input list always has exactly four strings - Even indices are 0 and 2 only - Join means concatenation, no separator


Problem Statement

Problem

Write a function join_even_index_strings(words) that takes a list of exactly four strings and returns a new string formed by joining the strings at even indices (index 0 and index 2).

Examples:

Call
join_even_index_strings(["apple", "banana", "cherry", "mango"])
Output
'applecherry'
Call
join_even_index_strings(["red", "green", "blue", "yellow"])
Output
'redblue'

Understanding the problem

A four-element list has indices 0, 1, 2, 3. The even ones are 0 and 2.

Index ["apple", "banana", "cherry", "mango"] Even?
0 "apple" ✅
1 "banana" ✗
2 "cherry" ✅
3 "mango" ✗

Result: "apple" + "cherry" = "applecherry"

Three ways to pick even indices

Since the list is always length 4, you can use direct indexing (words[0] + words[2]), slicing with step (words[::2]), or a general i % 2 == 0 check. All three give the same result here -- direct indexing is the simplest.


Solution approaches

def join_even_index_strings(words: list) -> str:
    # Even indices of a 4-element list are always 0 and 2
    first  = words[0]   # index 0 -- even
    second = words[2]   # index 2 -- even
    return first + second
def join_even_index_strings(words: list) -> str:
    # Slice with step 2 picks every other element starting at index 0
    return ''.join(words[::2])
join_even_index_strings = lambda words: ''.join(words[i] for i in range(0, len(words), 2))

Key takeaways

01

Slice with step: list[::2]

words[::2] returns every element at an even index -- words[0], words[2], words[4], … It works for any list length, not just four.

02

''.join(iterable) for concatenation

''.join([...]) concatenates all strings in an iterable with no separator. Cleaner than chaining + operators, especially when the number of elements can vary.

03

Fixed length vs. general solution

When the list is guaranteed to be length 4, words[0] + words[2] is perfectly valid and clear. For variable-length lists, prefer words[::2] or i % 2 == 0 so the logic scales.