Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69574 > unrolled thread
| Started by | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| First post | 2014-04-02 00:17 +0100 |
| Last post | 2014-04-04 11:52 +1000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
Compact way to assign values by slicing list in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-04-02 00:17 +0100
Re: Compact way to assign values by slicing list in Python Marco Buttu <marco.buttu@gmail.com> - 2014-04-03 15:50 +0200
Re: Compact way to assign values by slicing list in Python alex23 <wuwei23@gmail.com> - 2014-04-04 11:52 +1000
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-04-02 00:17 +0100 |
| Subject | Compact way to assign values by slicing list in Python |
| Message-ID | <mailman.8828.1396530054.18130.python-list@python.org> |
Came across this http://stackoverflow.com/questions/22756632/compact-way-to-assign-values-by-slicing-list-in-python?newsletter=1&nlcode=245176|202f - just curious what you guys and gals thought of the answers. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com
[toc] | [next] | [standalone]
| From | Marco Buttu <marco.buttu@gmail.com> |
|---|---|
| Date | 2014-04-03 15:50 +0200 |
| Message-ID | <lhjovl$sbn$1@speranza.aioe.org> |
| In reply to | #69574 |
On 04/02/2014 01:17 AM, Mark Lawrence wrote: > Came across this > http://stackoverflow.com/questions/22756632/compact-way-to-assign-values-by-slicing-list-in-python?newsletter=1&nlcode=245176|202f > - just curious what you guys and gals thought of the answers. I prefere this one: bar = ['a','b','c','x','y','z'] v1, _, _, v2, v3, _ = bar I also like the solution with itemgetter: v1, v2, v3 = itemgetter(0, 3, 4)(bar) but I think it is less readable than the previous one -- Marco Buttu
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2014-04-04 11:52 +1000 |
| Message-ID | <lhl38q$ung$1@dont-email.me> |
| In reply to | #69583 |
On 3/04/2014 11:50 PM, Marco Buttu wrote: > I prefere this one: > > bar = ['a','b','c','x','y','z'] > v1, _, _, v2, v3, _ = bar > > I also like the solution with itemgetter: > > v1, v2, v3 = itemgetter(0, 3, 4)(bar) > > but I think it is less readable than the previous one What if you wanted the 2nd, 37th, and 1007th items from a list? Personally, I find the 2nd form far more readable, once I got past my initial surprise that it would access a list of items.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web