Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62083
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: Concatenate string list to number list to form title - Logic needed. |
| Date | 2013-12-16 17:43 +0000 |
| References | <2333bfb4-cd72-4ed0-9b28-d8dbe26b5be2@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4225.1387215798.18130.python-list@python.org> (permalink) |
On 16/12/2013 17:16, Ravi Prabakaran wrote:
> Hi,
> I'm completely new to python. I just need simple logic to get output without any loops.
> I have list of string and list of list of numbers.
> Each string should be concatenated with every third and fourth values to generate proper titles in list of strings.
>
> t = ['Start','End']
> a = [[1,2,3,4],
> [5,6,7,8]]
>
> Expected Result : ( list of strings )
>
> ['Start - 3 , End - 4',
> 'Start - 7 , End - 8']
>
> Note : First 2 values from each list should be ignored.
>
> Could anyone please guide me with best solution without loops ?
>
> Thanks
> Ravi
>
I've no idea what your definition of "best" is but this works.
strings = ['{} - {} , {} - {}'.format(t[0], b[-2], t[1], b[-1]) for b in a]
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Concatenate string list to number list to form title - Logic needed. Ravi Prabakaran <ravi.itm@gmail.com> - 2013-12-16 09:16 -0800
Re: Concatenate string list to number list to form title - Logic needed. Chris Angelico <rosuav@gmail.com> - 2013-12-17 04:29 +1100
Re: Concatenate string list to number list to form title - Logic needed. Chris Angelico <rosuav@gmail.com> - 2013-12-17 04:51 +1100
Re: Concatenate string list to number list to form title - Logic needed. Chris Angelico <rosuav@gmail.com> - 2013-12-17 04:52 +1100
Re: Concatenate string list to number list to form title - Logic needed. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-16 17:43 +0000
Re: Concatenate string list to number list to form title - Logic needed. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-12-16 20:13 +0200
Re: Concatenate string list to number list to form title - Logic needed. Peter Otten <__peter__@web.de> - 2013-12-16 19:37 +0100
Re: Concatenate string list to number list to form title - Logic needed. John Gordon <gordon@panix.com> - 2013-12-16 18:50 +0000
Re: Concatenate string list to number list to form title - Logic needed. Terry Reedy <tjreedy@udel.edu> - 2013-12-16 15:23 -0500
csiph-web