Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60968

Re: The input and output is as wanted, but why error?

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: The input and output is as wanted, but why error?
Date 2013-12-03 17:54 -0500
Organization IISS Elusive Unicorn
References <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> <02798e66-515f-45d8-9f45-92f58b16642d@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3535.1386111296.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, 3 Dec 2013 08:35:20 -0800 (PST), geezle86@gmail.com declaimed the
following:

>> x = input() 
>> 
>> if x.isdigit() == False: 
>>     i = len(x) 
>>     j = i - 1 
>>     k = i - 2 
>> 
>>     xList = list(x) 
>> 
>>     if len(xList) > 4: 
>>         print(xList[0], int(k), xList[j], sep='', end='') 

	First off -- there is no need to turn the "word" into a list of
characters... You can index strings. x[0] is the first character, x[-1] is
the last.

	Second... k is already an integer, so there is no need to convert it
into an integer.

	Third... i, j, k aren't really needed -- for something this simple

	if not x.isdigit() and len(x) > 4:
		print ("%s%s%s" % (x[0], len(x)-2, x[-1])
	else:
		print (x)


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

The input and output is as wanted, but why error? geezle86@gmail.com - 2013-12-03 07:48 -0800
  Re: The input and output is as wanted, but why error? John Gordon <gordon@panix.com> - 2013-12-03 16:03 +0000
  Re: The input and output is as wanted, but why error? Neil Cerutti <neilc@norwich.edu> - 2013-12-03 16:10 +0000
  Re: The input and output is as wanted, but why error? geezle86@gmail.com - 2013-12-03 08:35 -0800
    Re: The input and output is as wanted, but why error? Dave Angel <davea@davea.name> - 2013-12-03 12:58 -0500
    Re: The input and output is as wanted, but why error? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-03 17:54 -0500
  Re: The input and output is as wanted, but why error? geezle86@gmail.com - 2013-12-03 08:36 -0800
    Re: The input and output is as wanted, but why error? Neil Cerutti <neilc@norwich.edu> - 2013-12-03 16:58 +0000
  Re: The input and output is as wanted, but why error? geezle86@gmail.com - 2013-12-03 08:38 -0800
    Re: The input and output is as wanted, but why error? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-03 16:51 +0000
  Re: The input and output is as wanted, but why error? rusi <rustompmody@gmail.com> - 2013-12-03 09:19 -0800
  Re: The input and output is as wanted, but why error? Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-03 23:52 +0000

csiph-web