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
#8
What happens if a word repeats? What about punctuation? Lose the punctuation?

I think there are already modules for doing this kind of thing.

from collections import Counter
sentence = "All work and no play makes Jack a dull boy. Jack is a dull boy. Work makes him dull."
words = sentence.split()
wordCount = Counter(words)
Output:
Counter({'Jack': 2, 'a': 2, 'dull': 2, 'boy.': 2, 'All': 1, 'work': 1, 'and': 1, 'no': 1, 'play': 1, 'makes': 1, 'is': 1})
type(wordCount)
Output:
<class 'collections.Counter'>
wordCount['Jack']
Output:
2
Reply


Messages In This Thread
RE: Create X Number of Variables and Assign Data - by Pedroski55 - Nov-13-2023, 12:06 PM

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,362 Oct-19-2023, 01:01 PM
Last Post: klllmmm
Question How create programmatically variables ? SpongeB0B 6 1,597 Aug-19-2023, 05:10 AM
Last Post: SpongeB0B
  Delete strings from a list to create a new only number list Dvdscot 8 1,780 May-01-2023, 09:06 PM
Last Post: deanhystad
  Create simple live plot of stock data dram 2 3,054 Jan-27-2023, 04:34 AM
Last Post: CucumberNox
  Create a function for writing to SQL data to csv mg24 4 1,306 Oct-01-2022, 04:30 AM
Last Post: mg24
  Best way to accommodate unknown number of variables? Mark17 9 4,014 May-30-2022, 03:57 AM
Last Post: Skaperen
  Create array of values from 2 variables paulo79 1 1,187 Apr-19-2022, 08:28 PM
Last Post: deanhystad
  How to create 2 dimensional variables in Python? plumberpy 5 2,018 Mar-31-2022, 03:15 AM
Last Post: plumberpy
  Strategy on updating edits back to data table and object variables hammer 0 1,248 Dec-11-2021, 02:58 PM
Last Post: hammer
  How can I assign "multiple variables" to a single "value"? Psycpus 2 1,948 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