Python Forum
Create X Number of Variables and Assign Data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create X Number of Variables and Assign Data
#9
I concur that dictionary or list is the way to go.

One way to create dictionary from sentence can be dictionary comprehension:

>>> sentence = "All work and no play makes Jack a dull boy."
>>> {f"var_{i}": v for i, v in enumerate(sentence.split())}
{'var_0': 'All', 'var_1': 'work', 'var_2': 'and', 'var_3': 'no', 'var_4': 'play', 'var_5': 'makes', 'var_6': 'Jack', 'var_7': 'a', 'var_8': 'dull', 'var_9': 'boy.'}
>>>
RockBlok likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Create X Number of Variables and Assign Data - by perfringo - Nov-14-2023, 08:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Better python library to create ER Diagram by using pandas data frames as tables klllmmm 0 1,312 Oct-19-2023, 01:01 PM
Last Post: klllmmm
Question How create programmatically variables ? SpongeB0B 6 1,515 Aug-19-2023, 05:10 AM
Last Post: SpongeB0B
  Delete strings from a list to create a new only number list Dvdscot 8 1,745 May-01-2023, 09:06 PM
Last Post: deanhystad
  Create simple live plot of stock data dram 2 3,026 Jan-27-2023, 04:34 AM
Last Post: CucumberNox
  Create a function for writing to SQL data to csv mg24 4 1,288 Oct-01-2022, 04:30 AM
Last Post: mg24
  Best way to accommodate unknown number of variables? Mark17 9 3,969 May-30-2022, 03:57 AM
Last Post: Skaperen
  Create array of values from 2 variables paulo79 1 1,172 Apr-19-2022, 08:28 PM
Last Post: deanhystad
  How to create 2 dimensional variables in Python? plumberpy 5 1,989 Mar-31-2022, 03:15 AM
Last Post: plumberpy
  Strategy on updating edits back to data table and object variables hammer 0 1,239 Dec-11-2021, 02:58 PM
Last Post: hammer
  How can I assign "multiple variables" to a single "value"? Psycpus 2 1,933 Oct-04-2021, 03:29 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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