Answers for "list add to list"

1

add to a list python

#append to list
lst = [1, 2, 3]
li = 4
lst.append(li)
#lst is now [1, 2, 3, 4]

.append("the add"): append the object to the end of the list.
.insert("the add"): inserts the object before the given index.
.extend("the add"): extends the list by appending elements from the iterable.
Posted by: Guest on November-22-2020
0

add to list

import tkinter as tk
from tkinter import simpledialog
from tkinter import messagebox
import json

ROOT = tk.Tk()
ROOT.withdraw()

number = 0
thelist = []

while(number < 3):
    USER_INP = simpledialog.askstring(title="List",
                                  prompt="Add 3 items:")
    thelist.append(USER_INP + ",")
    number = number + 1

with open("list.json", 'w') as f:
    json.dump(thelist, f, indent=2)

with open("list.json", 'r') as f:
    thelist = json.load(f)

messagebox.showinfo("The List", thelist)
Posted by: Guest on September-22-2021

Python Answers by Framework

Browse Popular Code Answers by Language