Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97007
| Subject | Re: Python, convert an integer into an index? |
|---|---|
| References | <e6e800a2-a64c-47dc-87b3-c6d32b6fca2f@googlegroups.com> <201509222221.t8MMLMi5015927@fido.openend.se> |
| From | MRAB <python@mrabarnett.plus.com> |
| Date | 2015-09-23 00:27 +0100 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.79.1442964432.28679.python-list@python.org> (permalink) |
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]
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python, convert an integer into an index? Chris Roberts <thecjguy1@gmail.com> - 2015-09-22 14:43 -0700
Re: Python, convert an integer into an index? Laura Creighton <lac@openend.se> - 2015-09-23 00:21 +0200
Re: Python, convert an integer into an index? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-23 00:23 +0100
Re: Python, convert an integer into an index? MRAB <python@mrabarnett.plus.com> - 2015-09-23 00:27 +0100
Re: Python, convert an integer into an index? marco.nawijn@colosso.nl - 2015-09-22 23:55 -0700
Re: Python, convert an integer into an index? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-22 23:13 -0400
Re: Python, convert an integer into an index? Anssi Saari <as@sci.fi> - 2015-09-23 12:01 +0300
Re: Python, convert an integer into an index? MRAB <python@mrabarnett.plus.com> - 2015-09-24 14:30 +0100
Re: Python, convert an integer into an index? jmp <jeanmichel@sequans.com> - 2015-09-24 16:14 +0200
Re: Python, convert an integer into an index? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-24 21:26 -0400
Re: Python, convert an integer into an index? Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-23 15:32 +0000
Re: Python, convert an integer into an index? Lorenzo Sutton <lorenzofsutton@gmail.com> - 2015-09-24 18:13 +0200
Re: Python, convert an integer into an index? Tim Daneliuk <tundra@bogus-city.tundraware.com> - 2015-09-23 10:55 -0500
csiph-web