Extending sequences with ellipsis in Python

Python ellipsis (...) Data Type: Exercise-8 with Solution

Write a Python program that uses Ellipsis to extend a sequence with another sequence.

Sample Solution:


# Define three sequences
sequence1 = [1, 2, 3]
sequence2 = [4, 5, 6]
sequence3 = [7, 8, 9]

# Extend sequence1, sequence2 and sequence3 using ellipsis
extended_sequence = sequence1 + [...] + sequence2 + [...] + sequence3

# Print the extended sequence


[1, 2, 3, Ellipsis, 4, 5, 6, Ellipsis, 7, 8, 9]

In the exercise above, we have three sequences, sequence1, sequence2 and sequence3. We use 'ellipsis (...)' between them to represent an extension operation. The result, extended_sequence, will contain the elements from sequence1, sequence2 and sequence3 concatenated together.


Flowchart: Extending sequences with ellipsis in Python.

Previous: Generating sequences with ellipsis in Python.
Next: Creating Python classes with dynamic attributes.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Follow us on Facebook and Twitter for latest update.