Combine Python Lists

Combine Python Lists using plus(+)


chars = ['a', 'b', 'c']

total_chars = chars + ['d', 'e']

print(total_items) # ['a', 'b', 'c', 'd', 'e']

Note: This approach not work for adding single item to the list, you can use .append(). Another approach to add one item is to create a new list with a single value and then use the plus symbol to add the list.

Comments

Popular posts from this blog

Interview Question on Ruby on Rails

Inserting and Moving elements inside Ruby Array