Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'element': 0.07; 'error:': 0.07; 'float': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'assume': 0.14; 'wrote': 0.14; 'enough.': 0.16; 'patil': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'res': 0.16; 'subject:non': 0.16; 'subject:type': 0.16; 'tuple': 0.16; 'tuple.': 0.16; 'tuples,': 0.16; 'typeerror:': 0.16; 'undefined.': 0.16; 'elements': 0.16; 'trying': 0.19; 'version.': 0.19; 'error': 0.23; 'code:': 0.26; 'header:X -Complaints-To:1': 0.27; '"",': 0.31; 'them?': 0.31; 'tuples': 0.31; 'file': 0.32; '(most': 0.33; 'problem': 0.35; "can't": 0.35; 'add': 0.35; 'sequence': 0.36; 'next': 0.36; "i'll": 0.36; 'hi,': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'easy': 0.60; 'show': 0.63; 'sum': 0.64; 'unclear': 0.84; 'subject::': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:TypeError: can't multiply sequence by non-int of type 'tuple' Date: Fri, 21 Feb 2014 06:28:14 -0500 (EST) Organization: news.gmane.org References: X-Gmane-NNTP-Posting-Host: dpc6744192008.direcpc.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392981874 news.xs4all.nl 2881 [2001:888:2000:d::a6]:44291 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66825 Jaydeep Patil Wrote in message: > HI, > > I have a tuple. I need to make sqaure of elements of tuple and after that i want add all suared tuple elements for total. When i trying to do it, below error came. > > > Code: > seriesxlist1 = ((0.0,), (0.01,), (0.02,), (0.03,), (0.04,), (0.05,), (0.06,), (0.07,), (0.08,), (0.09,), (0.1,), (0.11,)) > > x2 = [x * x for x in seriesxlist1]; > > Error: > Traceback (most recent call last): > File "", line 1, in > x2 = [x * x for x in seriesxlist1]; > TypeError: can't multiply sequence by non-int of type 'tuple' > The cause of the error is easy enough. (0.0,) * (0.0,) is undefined. It's unclear however what you actually intended because the problem is incompletely specified. Start with python version. I'll assume 3.3. Next show us what result you actually expect. Can we assume all tuples will have a single element in them? Are you looking to flatten both list and tuples, and get a single float sum? Wild guess: x2 = [x[0]* x[0] for x in seriesxlist1]; res = sum (x2) -- DaveA