Re: While loop - print several times but on 1 line.
Jeffrey Schwab wrote: > Danny wrote: > >> Great! It's been solved. >> >> The line, as Glaudio said has a "," at the end and that makes it go >> onto one line, thanks so much man! >> >> var = 0 >> while <= 5: >> print a[t[var]], >> var = var +1 >> prints perfectly, thanks so much guys. > > > > Looping over indexes is kinda unpythonic in its own right. Is there > something magical about the number 5? > > for e in t: > print a[e], Or if you want to just iterate over a part of t: start = 0 end = 6 # end is not included for e in t[start:end]: print a[e]* -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: > I think I should paste some of the programs code a little more of what I > want... probably... > var = 0 > while var <= 5: > print a[t[var]] > var = var +1 > > a is a dectionary (very big) and t is a string of text. (if that's > important right now). It might be important... > I'm just trying to make the value of a[t[var]] print on one line if that > makes any sense... > Sorry if I'm not explaining this very well and if my examples aren't > very good, I am trying. If I understand correctly, you have - a dict 'a' which may look like this: a = {'a': 1, 'b' : 2, 'c' : 3, #etc 'z' : 26 } that is, keys of this dict are one-letter-strings (we dont actually care what the real values are, enough to know that it's what you want to print out). - a string 't' which may look like this : t = 'abcdefghijklmnopqrstuvwxyz' And you want to print someting like: 12345 (that is, the dict values which have one of the 5 fisrt letters of t as keys) Is that what you actually want ? -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: > Great! It's been solved. > > The line, as Glaudio said has a "," at the end and that makes it go onto > one line, thanks so much man! > > var = 0 > while <= 5: > print a[t[var]], > var = var +1 > prints perfectly, thanks so much guys. Looping over indexes is kinda unpythonic in its own right. Is there something magical about the number 5? for e in t: print a[e], -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny <[EMAIL PROTECTED]> wrote: >The programs output will be: >text >text >(etc) > >How could I make this print: texttexttexttexttext? >Ive researched and looked through google and so far I can't find >anything that will help (or revelent for that matter). I'm kind of surprised this isn't a FAQ (if it's in the FAQs, I can't find it). http://docs.python.org/tut/node5.html#SECTION00520 tells you how to use print "text", # Note the comma. Oh, and the correct comment character. to get text text text text text http://docs.python.org/tut/node9.html#SECTION00910 hints that what you want may be sys.stdout.write("text") to get texttexttexttexttext Beware that in either case you'll need an additional print at the end of the loop to get the final newline back. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: > Great! It's been solved. > > The line, as Glaudio said has a "," at the end and that makes it go onto > one line, thanks so much man! > > var = 0 > while <= 5: >print a[t[var]], >var = var +1 > prints perfectly, thanks so much guys. if you wanted spaces between the items, why didn't you say that ? > How could I make this print: texttexttexttexttext? >>> for i in range(5): ... print "text" ... text text text text text >>> for i in range(5): ... print "text", ... text text text text text >>> import sys >>> for i in range(5): ... sys.stdout.write("text") ... texttexttexttexttext >>> oh well. -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: > I think I should paste some of the programs code a little more of what I > want... > > var = 0 > while var <= 5: > print a[t[var]] > var = var +1 > > a is a dectionary (very big) and t is a string of text. (if that's > important right now). > > I'm just trying to make the value of a[t[var]] print on one line if that > makes any sense... if you don't want print's behaviour, you can print directly to the stdout stream: import sys for var in range(5): sys.stdout.write(a[t[var]]) write only accepts strings, so if the dictionary may contain other stuff, you need to use the str() function to convert the data on the way out: for var in range(5): sys.stdout.write(str(a[t[var]])) -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Great! It's been solved. The line, as Glaudio said has a "," at the end and that makes it go onto one line, thanks so much man! var = 0 while <= 5: print a[t[var]], var = var +1 prints perfectly, thanks so much guys. -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: > I think I should paste some of the programs code a little more of what I > want... > > var = 0 > while var <= 5: > print a[t[var]] > var = var +1 > > a is a dectionary (very big) and t is a string of text. (if that's > important right now). > > I'm just trying to make the value of a[t[var]] print on one line if that > makes any sense... > Sorry if I'm not explaining this very well and if my examples aren't > very good, I am trying. I mean that what you are looking for is: print a[t[var]], Notice the last comma in the line above. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
I think I should paste some of the programs code a little more of what I want... var = 0 while var <= 5: print a[t[var]] var = var +1 a is a dectionary (very big) and t is a string of text. (if that's important right now). I'm just trying to make the value of a[t[var]] print on one line if that makes any sense... Sorry if I'm not explaining this very well and if my examples aren't very good, I am trying. -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: > How could I make this print: texttexttexttexttext? > Ive researched and looked through google and so far I can't find > anything that will help (or revelent for that matter). I am not quite sure, if I simplify the problem but i thought about something like that: >>> print "text"*5 texttexttexttexttext cheers Stefan pgp470Yem6sNX.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: > As a shortcut: print "text"*5 --- Heiko. -- http://mail.python.org/mailman/listinfo/python-list
Re: While loop - print several times but on 1 line.
Danny wrote: > Hello there. > > I'm creating a little text changer in Python. In the program there is a > while loop. The problem is that a while loop will have 1 print statement > and it will loop until it gets to the end of the text. > Example: > > num = 5 // Set num to 5 > while num >= 1: // loop 5 times. > print """text""" > num = num-1 > // end. Don't use while for that, this is considered unpythonix. Use a for-loop with xrange instead. If you need the nums in that order, use xrange with a negative step: Use sys.stdout.write: import sys for i in xrange(num, 0, -1): sys.stdout.write("text") Diez -- http://mail.python.org/mailman/listinfo/python-list
While loop - print several times but on 1 line.
Hello there. I'm creating a little text changer in Python. In the program there is a while loop. The problem is that a while loop will have 1 print statement and it will loop until it gets to the end of the text. Example: num = 5 // Set num to 5 while num >= 1: // loop 5 times. print """text""" num = num-1 // end. The programs output will be: text text (etc) How could I make this print: texttexttexttexttext? Ive researched and looked through google and so far I can't find anything that will help (or revelent for that matter). Thanks for looking. -- http://mail.python.org/mailman/listinfo/python-list