473,410 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Beginning programmer question - How to print a list in a different format

Hi.

I have a dictionary thus: (wraps)

p1hand =
{'b12':b12,'d12':d12,'d23':d23,'n12':n12,'n23':n23 ,'n34':n34,'p12':p12,'
p23':p23,'p34':p34,'p45':p45}

I set a variable called p1handlist so that I can print a list of the
keys to the screen:

p1handlist = p1hand.keys()
print p1handlist

and the output looks like this:

['b12', 'd12', 'd23', 'n12', 'n23', 'n34', 'p12', 'p23', 'p34', 'p45']

how can I make it so that the output looks more like this?:

b12, d12, d23, n12, n23, n34, p12, p23, p34, p45

This is for a simple text mode game I am writing and the output to the
screen is important because at times the list gets too big to print on
one line of the display.

Thanks!

John

Jul 18 '05 #1
2 1245
John wrote:
Hi.

I have a dictionary thus: (wraps)

p1hand =
{'b12':b12,'d12':d12,'d23':d23,'n12':n12,'n23':n23 ,'n34':n34,'p12':p12,'
p23':p23,'p34':p34,'p45':p45}

I set a variable called p1handlist so that I can print a list of the
keys to the screen:

p1handlist = p1hand.keys()
print p1handlist

and the output looks like this:

['b12', 'd12', 'd23', 'n12', 'n23', 'n34', 'p12', 'p23', 'p34', 'p45']

how can I make it so that the output looks more like this?:

b12, d12, d23, n12, n23, n34, p12, p23, p34, p45
You can do something like this:

toPrint = ", ".join(p1handlist)
print toPrint
This is for a simple text mode game I am writing and the output to the
screen is important because at times the list gets too big to print on
one line of the display.


You might want to split the list first and then join the sublists.

--
Andres Rosado
Email: an*****@despammed.com
ICQ: 66750646
AIM: pantear
Homepage: http://andres980.tripod.com/

Every election is a sort of advance auction sale of stolen goods.
-- H.L. Mencken
Jul 18 '05 #2
In article <MP************************@news-server.columbus.rr.com>,
Jo**@the.computer says...
Hi.

I have a dictionary thus: (wraps)

p1hand =
{'b12':b12,'d12':d12,'d23':d23,'n12':n12,'n23':n23 ,'n34':n34,'p12':p12,'
p23':p23,'p34':p34,'p45':p45}

I set a variable called p1handlist so that I can print a list of the
keys to the screen:

p1handlist = p1hand.keys()
print p1handlist

and the output looks like this:

['b12', 'd12', 'd23', 'n12', 'n23', 'n34', 'p12', 'p23', 'p34', 'p45']

how can I make it so that the output looks more like this?:

b12, d12, d23, n12, n23, n34, p12, p23, p34, p45

This is for a simple text mode game I am writing and the output to the
screen is important because at times the list gets too big to print on
one line of the display.

Thanks!

John

Robert & Andres,
Thanks so much for the help. As it turns out:
print ', '.join(p1handlist)


does the trick! You have made me look like a genius! :)

John
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn'...
5
by: middletree | last post by:
I did a search in this forum, as well as at www.asp.faq.com, and MSDN, and would like to know how to use ASP to build a report and create an .xls file as a result. I've seen lots of tutorials...
7
by: gk245 | last post by:
I have this: #include <stdio.h> int main (void) { int number; printf ("Enter number: ");
11
by: Lint Radley | last post by:
Hi Everyone, I've done several C# console applications now, and feel comfortable with the language. Can anyone recommend a web site, book, etc which has information on starting to develop full...
8
by: sam_cit | last post by:
Hi, I hear many say that it is better to convert address, i mean, type cast into (void*) and print using %p identifier rather than %u, could you let me know the specific reason behind it?
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
38
by: joeschnell | last post by:
First week of the current trimester and we've taken a huge leap from writing little code snippets of loops and switches to writing an entire program, and expecting it to work! I, nor anyone else in...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
5
by: sniipe | last post by:
Hi, I have a problem with unicode string in Pylons templates(Mako). I will print first char from my string encoded in UTF-8 and urllib.quote(), for example string 'Łukasz': ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.