Path: csiph.com!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!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:Python': 0.05; 'strings.': 0.07; '[1,': 0.09; 'creighton': 0.09; 'subject:into': 0.09; 'successive': 0.09; 'python': 0.10; 'index': 0.13; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'integers,': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'url:tutor': 0.16; 'wrote:': 0.16; 'string': 0.17; 'first.': 0.18; 'laura': 0.18; '>>>': 0.20; '2015': 0.20; 'fairly': 0.22; 'int,': 0.22; 'sep': 0.22; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'chris': 0.26; 'back.': 0.27; 'this.': 0.28; '-0700,': 0.29; 'character': 0.29; 'convert': 0.29; 'url:mailman': 0.30; 'url:python': 0.33; 'shorter': 0.33; 'url:listinfo': 0.34; 'tue,': 0.34; 'list': 0.34; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'assigned': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'list.': 0.37; 'wanted': 0.37; 'mailing': 0.38; 'received:192': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'easy': 0.60; 'your': 0.60; 'back': 0.62; 'tutor': 0.66; 'results': 0.66 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=CvRCCSMD c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=IkcTkHD0fZMA:10 a=8AHkEIZyAAAA:8 a=Jv9h3AXjujB2Mg7vKZ0A:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Subject: Re: Python, convert an integer into an index? To: python-list@python.org References: <201509222221.t8MMLMi5015927@fido.openend.se> From: MRAB Date: Wed, 23 Sep 2015 00:27:03 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <201509222221.t8MMLMi5015927@fido.openend.se> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442964432 news.xs4all.nl 23769 [2001:888:2000:d::a6]:56931 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97007 On 2015-09-22 23:21, Laura Creighton wrote: > In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes: >> >> >>(How do I make it into an index? ) >>Preferably something fairly easy to understand as I am new at this. >> >>results = 134523 #(Integer) >> >>Desired: >>results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) >> >>Somehow I see ways to convert index to list to int, but not back again. >> >>Thanks, >>crzzy1 > > You need to convert your results into a string first. > > result_int=1234523 > result_list=[] > > for digit in str(result_int): > result_list.append(int(digit)) > > digit will be assigned to successive 1 character long strings. Since > you wanted a list of integers, you have to convert it back. > > If you are learning python you may be interested in the tutor mailing > list. https://mail.python.org/mailman/listinfo/tutor > A shorter way using strings: >>> results = 134523 >>> list(map(int, str(results))) [1, 3, 4, 5, 2, 3]