Python Forum
creating a list during program execution.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating a list during program execution.
#1
Is there any way of writing code, that will allow python to create
a list during the program execution. As of now I understand, that you
have to define a list in the hard coding process. But I would like to be
able to create a list as the program is executing, the commands.

Is this possible?
Thank you for anyone taking the time to answer this question.
Reply
#2
Totally. Very common operation:

# file to list
data = open('data_file.txt').readlines()

# string to list
text = input('Type in a sentence: ')
words = text.split()

# build from numbers
fib = [1, 1]
for index in range(100):
    fib.append(fib[-1] + fib[-2])
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thank you for the helpful reply.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  kill python execution program lebossejames 0 238 Mar-16-2024, 11:16 AM
Last Post: lebossejames
  Program to find Mode of a list PythonBoy 6 1,077 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,917 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  creating simplex tableau pivot program easy or difficult for a beginner in Python? alex_0 2 2,573 Mar-31-2021, 03:39 AM
Last Post: Larz60+
  Creating list of lists from generator object t4keheart 1 2,202 Nov-13-2020, 04:59 AM
Last Post: perfringo
  Creating a dictionary from a list Inkanus 5 3,158 Nov-06-2020, 06:11 PM
Last Post: DeaD_EyE
  Creating a list of dictionaries while iterating pythonnewbie138 6 3,272 Sep-27-2020, 08:23 PM
Last Post: pythonnewbie138
  Creating a list of RSSI value and send it to the server. Azuan 0 2,645 Jun-08-2020, 11:22 PM
Last Post: Azuan
  Python - change variable type during program execution ple 1 2,373 Apr-12-2020, 08:43 AM
Last Post: buran
  creating a list of dictionaries from API calls AndrewEnglsh101 5 3,068 Apr-03-2020, 02:21 PM
Last Post: AndrewEnglsh101

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020