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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:13:43+00:00 2026-06-17T04:13:43+00:00

I want to transform list to a string, but it contains integers. It works

  • 0

I want to transform list to a string, but it contains integers. It works now, anyway that’s the code:

for player in basicPlayers:
  say('Name' + str(player['name']) + 'score' + str(player['score']))

Sooo yeah, I want to make it like

Player1 (2), Player2 (4), Player3 (6)

not

Player1 (2) 
Player2 (4)
Player3 (6)

The code that gets the data:

def getBasicPlayers(self): # Finished
        """Returns a list containing a dictionary for each player:
        [
            {
                'name' : string,
                'score' : integer,
            },
            {
                'name' : string,
                'score' : integer,
            },
        ]
        Note: This will return an empty list if the player count is above 100."""
        packet = self.assemblePacket("c")
        self.send(packet)

        reply = self.receive()
        reply = reply[11:] # Clean up bytes
        players = []

        strLen = struct.unpack("<h", reply[0:2])
        playerCount = strLen[0]

        reply = reply[2:] # Clean up bytes

        for i in range(playerCount):
            players.append({'name' : '', 'score' : 0})

        pointer = 0

        for player in players:
            strLen = ord(reply[pointer:(pointer + 1)])

            name = reply[(pointer + 1):(pointer + (strLen + 1))]

            temp = struct.unpack("<i", reply[(pointer + (strLen + 1)):(pointer + (strLen + 5))])
            pointer += (strLen + 5)

            player['name'] = name
            player['score'] = temp[0]

        return players
  • 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-17T04:13:44+00:00Added an answer on June 17, 2026 at 4:13 am

    How about

    ', '.join('Name %(name)s Score %(score)d' % player for player in basicPlayers)
    

    Note that join takes any iterable as its argument, in this case we pass a generator expression to it.


    For example:

    basicPlayers = [{'name' : 'Bob','score' : 42}, {'name' : 'Joe','score' : 24}]
    
    print ', '.join('Name %(name)s Score %(score)d' % 
                                               player for player in basicPlayers)
    
    Name Bob Score 42, Name Joe Score 24
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In F# I want to transform a list of chars into a string. Consider
I want to transform a List[Option[T]] into a Option[List[T]] . The signature type of
I want to transform the dataset list, where the row is composed of different
So i want to show a contacts list and for that I have transformed
I'm using XSLT 1.0 an want to transform an XML file. It works fine
The inverse question of How can I transform XML into a List or String[]?
I wrote some parser from combinatory library. I want a generic function that transform
i have this code: public class Test{ arrayList<String> list = new ArrayList<String>(); String[][] temp_list;
I use @XmlJavaTypeAdapter to transform Map<String, MapItem> objects into List<MapItem> when marshalling (and vice
Let's say I have a target string (or list, doesn't really matter) of some

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.