Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:39:40+00:00 2026-06-06T14:39:40+00:00

I’m very new to Python and I’m sure there is a much easier way

  • 0

I’m very new to Python and I’m sure there is a much easier way to accomplish what I need but here goes.

I’m trying to create a program which performs frequency analysis on a list of letters called inputList and retrives the 2 letter pairs and adds them to another dictionary. So I need it to populate a second dictonary with all the 2 letter pairs.

I have a rough idea how I can do this but am I bit stuck with the syntax to make it work.

for bigram in inputList:
    bigramDict[str(bigram + bigram+1)] =  1

Where bigram+1 is the letter in the next iteration

As an example if I was to have the text “stackoverflow” in the inputList I need to to first put the letters “st” as the key and 1 as the value. On the second iteration “ta” as the key and so on. The problem I’m having is retriving the value the variable will be on the next iteration without moving to the next iteration.

I hope I explained myself clearly. Thanks for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:39:41+00:00Added an answer on June 6, 2026 at 2:39 pm

    A straightforward way to obtain n-grams for a sequence is slicing:

    def ngrams(seq, n=2):
        return [seq[i:i+n] for i in range(len(seq) - n + 1)]
    

    Combine this with collections.Counter and you’re ready:

    from collections import Counter
    print Counter(ngrams("abbabcbabbabr"))
    

    In case you need ngrams() to be lazy:

    from collections import deque
    
    def ngrams(it, n=2):
        it = iter(it)
        deq = deque(it, maxlen=n)
        yield tuple(deq)
        for p in it:
            deq.append(p)
            yield tuple(deq)
    

    (See below for more elegant code for the latter).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.