Skip to content

Instantly share code, notes, and snippets.

@raveensrk
Created August 30, 2023 12:33
Show Gist options
  • Save raveensrk/89bc3a0f6bfc6deb1b2d8700aafe65a5 to your computer and use it in GitHub Desktop.
Save raveensrk/89bc3a0f6bfc6deb1b2d8700aafe65a5 to your computer and use it in GitHub Desktop.
In python, How to append one list to another list?

You can append the new_options list to another list using the extend() method or the += operator. Here's how you can do it:

# Your new_options list
new_options = [
    {
        "shortname": "-clean",
        "help": "Cleans run directory",
        "required": True,
        "default": False,
        "datatype": bool
    }
]

# Another list to which you want to append new_options
existing_list = []

# Using the extend() method
existing_list.extend(new_options)

# OR using the += operator
# existing_list += new_options

print(existing_list)

Just replace existing_list with the name of the list to which you want to append new_options. Either the extend() method or the += operator will add the elements from new_options to the end of existing_list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment