Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71531
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; '(at': 0.04; 'string': 0.09; 'beginners': 0.09; 'indeed,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runs': 0.10; 'python': 0.11; 'def': 0.12; 'windows': 0.15; 'behaviour.': 0.16; 'characters:': 0.16; 'different;': 0.16; 'finney': 0.16; 'invisible': 0.16; 'iteration': 0.16; 'looping': 0.16; 'loops': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'space)': 0.16; 'tab': 0.16; 'tutoring': 0.16; 'url:tutor': 0.16; ':-)': 0.16; 'code.': 0.18; 'basically': 0.19; 'separate': 0.22; 'header:User-Agent:1': 0.23; "aren't": 0.24; 'question': 0.24; 'define': 0.26; 'header:X-Complaints-To:1': 0.27; 'character': 0.29; 'characters': 0.30; 'is?': 0.30; 'url:mailman': 0.30; 'indentation': 0.31; 'writes:': 0.31; 'file': 0.32; 'run': 0.32; 'text': 0.33; 'url:python': 0.33; 'something': 0.35; 'definition': 0.35; 'objects': 0.35; 'there': 0.35; 'curious': 0.36; 'false': 0.36; 'returning': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'subject:New': 0.37; 'too': 0.37; 'easily': 0.37; 'starting': 0.37; 'skip:o 20': 0.38; 'ben': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'space': 0.40; 'url:mail': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'is.': 0.60; 'forum': 0.61; 'url:3': 0.61; 'simple': 0.61; 'different': 0.65; 'here': 0.66; 'subject:. ': 0.67; 'products': 0.71; 'subject:For': 0.78; '2002': 0.81; 'engineered': 0.84; 'fin': 0.84; 'received:125': 0.84; 'shock': 0.84; 'treating': 0.84; 'differences': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Ben Finney <ben@benfinney.id.au> |
| Subject | Re: New to Python. For in loops curiosity |
| Date | Wed, 14 May 2014 14:03:08 +1000 |
| References | <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | jigong.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
| Cancel-Lock | sha1:lQ93ZL82i8u/Zk0md2W4pwj8yGo= |
| 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.9990.1400040202.18130.python-list@python.org> (permalink) |
| Lines | 60 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1400040202 news.xs4all.nl 2923 [2001:888:2000:d::a6]:46717 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:71531 |
Show key headers only | View raw
Leonardo Petry <leonardo.petry.br@gmail.com> writes:
> So I am starting with python and I have been working on some simple
> exercises.
You are welcome here. Congratulations on starting with Python!
You may also be interested to know there is also a separate forum
<URL:https://mail.python.org/mailman/listinfo/tutor> dedicated to
tutoring beginners in Python.
> Here is something I found curious about python loops
>
> This loop run each character in a string
>
> def avoids(word,letters):
> flag = True
> for letter in letters:
> if(letter in word):
> flag = False
> return flag
You should avoid using U+0009 TAB characters for indentation, since they
render inconsistently and can easily result in invisible differences in
changed code. Instead, use four-column indentation with space (U+0020
SPACE) characters.
> The loop below (at the bottom) runs each line of the file
>
> fin = open('wordplay.txt');
> user_input = raw_input('Enter some characters: ')
> count = 0
> for line in fin:
> word = line.strip()
> if(avoids(word, user_input)):
> count += 1;
>
> This is just too convenient.
Is that a complaint, or shock at how easy it is? :-)
> Basically my question is: Why is python not treating the contents of
> wordplay.txt as one long string and looping each character?
Because the types of the objects are different; different types define
different behaviour. Indeed, that is almost the definition of what a
type is.
A text string object supports iteration by returning each character
<URL:https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str>.
A file object supports iteration by returning each line from the stream
<URL:https://docs.python.org/3/library/io.html>.
--
\ “Our products just aren't engineered for security.” —Brian |
`\ Valentine, senior vice-president of Microsoft Windows |
_o__) development, 2002 |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
New to Python. For in loops curiosity Leonardo Petry <leonardo.petry.br@gmail.com> - 2014-05-13 20:38 -0700 Re: New to Python. For in loops curiosity John Gordon <gordon@panix.com> - 2014-05-14 03:46 +0000 Re: New to Python. For in loops curiosity Rustom Mody <rustompmody@gmail.com> - 2014-05-13 20:48 -0700 Re: New to Python. For in loops curiosity Ian Kelly <ian.g.kelly@gmail.com> - 2014-05-13 21:49 -0600 Re: New to Python. For in loops curiosity Ben Finney <ben@benfinney.id.au> - 2014-05-14 14:03 +1000 Re: New to Python. For in loops curiosity Roy Smith <roy@panix.com> - 2014-05-14 07:38 -0400 Re: New to Python. For in loops curiosity Ned Batchelder <ned@nedbatchelder.com> - 2014-05-14 09:41 -0400
csiph-web