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 8808787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:42:33+00:00 2026-06-14T02:42:33+00:00

Possible Duplicate: Function printing correct Output and None Trying to print mutual users in

  • 0

Possible Duplicate:
Function printing correct Output and None

Trying to print mutual users in a pretend twitter feed program. Homework. The numbers are users (ex 1111 is a user). The following set in the dictionary is a set of the key’s friends.

I’d like this output:

Most friends in common
1111:   222 33333 5454
222:    1111 33333 5454
33333:  1111 222
5454:   1111 222

But instead have this output:

Most friends in common
1111 :  222 33333 5454  1111 None
222 :   1111 33333 5454  222 None
33333 :  1111 222  33333 None
5454 :   1111 222  5454 None

Here is my program:

all_users = {'1111': set(['5454', '222']), '33333': set(['5454']), '5454': set(['1111', '33333', '222']), '222': set(['1111', '5454'])}



def findmutual(id, all_users):
    users = []
    for key in all_users:
        mutual = all_users[id].intersection(all_users[key])
        rank = len(mutual)
        templist = [rank, key.strip()]
        users.append(templist)
    users = sorted(users)

    print users

    for item in users:
        if  id == item[1]:
            print "" ,
        if item[0] == 0:
            print "",
        else:
            print item[1],


users = []
for key in all_users:
    users.append(key)
users = sorted(users)
print "Most friends in common"
for item in users:
    print item, ":\t", findmutual(item, all_users)

Please help me to understand this issue!

  • 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-14T02:42:35+00:00Added an answer on June 14, 2026 at 2:42 am
    for item in users:
        print item, ":\t", findmutual(item, all_users) # << That's why it shows None
    

    What is happening here?

    1. item = users[n]
    2. print:
      1. item
      2. enter the function
      3. the function prints some more
      4. function ends and (automatically) returns None
      5. print the return value (which is None) of the function!

    You probably want to change step 3-4!
    instead of all print statements smth like:

    result=''
    ...
    result += '' #whatever
    ...
    return result
    

    UPDATE:

    If i get you right, you are trying to establish a rank depending on who’s the most popular?

    In that case you might look int othat solution:

    all_users = {'1111': set(['5454', '222']),
                 '33333': set(['5454']),
                 '5454': set(['1111', '33333', '222']),
                 '222': set(['1111', '5454'])}
    
    from collections import defaultdict, Counter
    
    def findmutual(user_relation_map):    
        user_list = set(sorted(user_relation_map.keys()))
        user_ranking = defaultdict(int)
        for user in user_list:
            for friend in user_relation_map[user]:
                user_ranking[friend] += 1
        return user_ranking
    
    c=Counter(findmutual(all_users))
    print("Ranking : {0}".format(c.most_common()))
    
    >>> Ranking : [('5454', 3), ('1111', 2), ('222', 2), ('33333', 1)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Difference between (function(){})(); and function(){}(); I am trying to understand a few
Possible Duplicate: pthread Function from a Class I am trying to create a thread
Possible Duplicate: Printing of Array public function computeGHComponents() { error_reporting (E_ALL^ E_NOTICE); $total =
Possible Duplicate: function in setInterval() executes without delay I am trying to use setTimeOut
Possible Duplicate: returning multiple values from a function I'm trying to make a doubly
Possible Duplicate: PHP function to strip tags, except a list of whitelisted tags and
Possible Duplicate: JavaScript Function Definition in ASP User Control Hi, I have a generic
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
Possible Duplicate: Faster DirectoryExists function? I want to check if some file exists on

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.