To generate bigrams:
In [8]: b='student'
In [9]: [b[i:i+2] for i in range(len(b)-1)]
Out[9]: ['st', 'tu', 'ud', 'de', 'en', 'nt']
To generalize to a different n
:
In [10]: n=4
In [11]: [b[i:i+n] for i in range(len(b)-n+1)]
Out[11]: ['stud', 'tude', 'uden', 'dent']
More Related Contents:
- %d format: a number is required not list
- How can i calculate Caltalan numbers without a for loop?
- How to run independent transformations in parallel using PySpark?
- Installing Pygame on 64-bit Windows 7 and 64-bit Python 2.7
- Set scientific notation with fixed exponent and significant digits for multiple subplots
- connected component labeling in python
- cv2.imread always returns NoneType
- unknown error: call function result missing ‘value’ for Selenium Send Keys even after chromedriver upgrade
- “This browser or app may not be secure” error while attempting to login in to Gmail account using GeckoDriver Firefox through Selenium and Python
- How to control the download of files with Selenium + Python bindings in Chrome
- vscode import error for python module
- GAE ndb design, performance and use of repeated properties
- appcfg.py not working in command line
- Pip does not work after upgrade to ubuntu-16.10
- Using Multiple Databases with django
- How do I install Keras and Theano in Anaconda Python on Windows?
- Pyspark filter dataframe by columns of another dataframe
- How to Navigate to a New Webpage In Selenium?
- ImportError when importing certain modules from SciPY
- How can I pass arguments into redirect(url_for()) of Flask?
- AWS python lambda function:No module named requests
- Pandas Bad Lines Warning Capture
- Why doesn’t chained (interval) comparison work on numpy arrays?
- How does python’s time.time() method work?
- Using my own corpus instead of movie_reviews corpus for Classification in NLTK
- src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory
- Move and replace if same file name already exists?
- Horizontal scrolling won’t activate for ttk Treeview widget
- How to fit a 2D ellipse to given points
- How to download specific Google Drive folder using Python?