Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62083

Re: Concatenate string list to number list to form title - Logic needed.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'from:addr:yahoo.co.uk': 0.04; 'output': 0.05; 'subject:form': 0.07; 'string': 0.09; 'lawrence': 0.09; 'logic': 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; 'subject:number': 0.09; 'subject:string': 0.09; 'works.': 0.09; 'language.': 0.14; 'concatenated': 0.16; 'loops': 0.16; 'ravi': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'language': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; "i've": 0.25; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'ignored.': 0.30; 'subject:list': 0.30; "i'm": 0.30; 'anyone': 0.31; 'third': 0.33; 'could': 0.34; 'definition': 0.35; 'but': 0.35; 'thanks': 0.36; 'hi,': 0.36; 'should': 0.36; 'list': 0.37; 'expected': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'new': 0.61; 'simple': 0.61; 'first': 0.61; 'our': 0.64; 'fourth': 0.84; 'subject:needed.': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Concatenate string list to number list to form title - Logic needed.
Date Mon, 16 Dec 2013 17:43:04 +0000
References <2333bfb4-cd72-4ed0-9b28-d8dbe26b5be2@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-16-207.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To <2333bfb4-cd72-4ed0-9b28-d8dbe26b5be2@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4225.1387215798.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387215798 news.xs4all.nl 2851 [2001:888:2000:d::a6]:51546
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62083

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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