Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'else:': 0.03; 'character,': 0.09; 'len(x)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'strings.': 0.09; '"word"': 0.16; 'false:': 0.16; 'integer,': 0.16; 'integer.': 0.16; 'message-id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'index': 0.16; 'print': 0.22; "aren't": 0.24; 'url:home': 0.24; 'header:X-Complaints-To:1': 0.27; 'dec': 0.30; 'something': 0.35; 'convert': 0.35; 'there': 0.35; 'really': 0.36; 'charset:us- ascii': 0.36; 'subject:?': 0.36; 'turn': 0.37; 'list': 0.37; 'received:76': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'simple': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'subject:The': 0.64; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: The input and output is as wanted, but why error? Date: Tue, 03 Dec 2013 17:54:41 -0500 Organization: IISS Elusive Unicorn References: <387f5b5f-faf1-4715-8d49-e366be53fd00@googlegroups.com> <02798e66-515f-45d8-9f45-92f58b16642d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-27-178.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386111297 news.xs4all.nl 2908 [2001:888:2000:d::a6]:53344 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60968 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/