Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'elements.': 0.05; 'assign': 0.07; 'type,': 0.07; 'executes': 0.09; 'imply': 0.09; 'titles,': 0.09; 'tuple': 0.09; "wouldn't": 0.11; 'ignore': 0.13; 'passing': 0.15; '(x,': 0.16; 'authors.': 0.16; 'expects': 0.16; 'guessing': 0.16; 'saying.': 0.16; 'wrote:': 0.17; 'variables': 0.17; 'saying': 0.18; 'memory': 0.18; 'trying': 0.21; 'meant': 0.21; 'flags': 0.22; 'tuples': 0.22; 'runs': 0.22; "i've": 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'guess': 0.27; 'noticed': 0.28; 'represent': 0.28; 'checking.': 0.29; 'loop,': 0.29; 'str': 0.29; 'strings,': 0.29; 'way?': 0.29; "i'm": 0.29; 'maybe': 0.29; 'normally': 0.30; 'code': 0.31; 'generally': 0.32; 'help,': 0.32; 'could': 0.32; 'to:addr:python- list': 0.33; 'faster': 0.35; 'expected': 0.35; 'pm,': 0.35; 'there': 0.35; 'but': 0.36; 'method': 0.36; 'two': 0.37; 'item': 0.37; 'skip:z 10': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'received:192': 0.39; 'called': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'think': 0.40; 'real': 0.61; 'telling': 0.61; 'times': 0.63; 'received:74.208': 0.71; 'paper': 0.78; 'clearer': 0.84; 'received:74.208.4.194': 0.84; 'subject:better': 0.84; 'str.': 0.91 Date: Tue, 12 Feb 2013 15:33:25 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: A better way to accomplish loop References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:D3Uoe7WiP0eBGv6ktbap2HyKPlWZhq2Lw8okkpDPGbl RLgf9vuW46VWLfmtGf+lzQTc/gVKcoug8XGHFottTVAjzind9+ uqnCZ9TY0KbSf3A8qQ7odkUgNLRArG/ePW6cD9sF+tPKxoguew NRkpvOBOlo4WDymwfJjiCBNGnImZGQfyTFtkmjNbyiecShWB1w TSCYfd/BXkz1qKDT7bs/XGrvFc6mYz0dnG0RoEbNNxfNzNT3qy xmug0kw4KQCryU8kamWyflxehQ/XVChjqVyLNdoH+AzFdWrWeW 0dzmjamY7pFWFHQyX0fCUAWsIyjrJfbI4r7Wty8HSnb05xiPA= = 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360701231 news.xs4all.nl 6986 [2001:888:2000:d::a6]:39359 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38781 On 02/12/2013 02:59 PM, Joseph L. Casale wrote: > I have an issue with some code I have been passed: I had to read it about four times before I knew what you were saying. Maybe I still have it wrong. > > for (x, y) in [(a_dict1, a_tuple[0]), (a_dict2, a_tuple[1])]: > > > I only noticed it as PyCharm failed to assign the str type to y, whereas it knew > the tuples 0 and 1 item were type str. I think you're saying that the lint-feature of PyCharm is trying to guess the object types, and telling you there's a conflict here. I don't think you're saying that it executes incorrectly. > > > In the loop it flags the passing of y into a method that expects type str. I can ignore > it, but looking at the loop, I cant help but think there is a better way? > By better, you could have meant 1) clearer for the reader 2) runs faster or takes less memory 3) fools PyCharm into guessing better in its checking. If it's #3, then I'm no real help, as I've never seen a paper on the philosophy of the PyCharm guesser. Still there are ways to express it differently, and maybe one of them will happen to please PyCharm. Name the variables to represent what they're holding. Those names might also imply type, though I wouldn't normally go out of my way to accomplish it. But if the two parts of the two tuple are strings, perhaps the tuple as a whole might be called names, or titles, or authors. However, generally a tuple is NOT expected to have the same type for all its elements. for x,y in zip((a_dict1, a_dict2), a_tuple): dicts = [a_dict1, a_dict2] for x,y in zip(dicts, a_tuple): -- DaveA