Re: Bringing Order to programming

2019-01-31 Thread Ben Bacarisse
r...@zedat.fu-berlin.de (Stefan Ram) writes:

> source = \
> 'Python is an easy to learn, powerful programming language. It has' + \
> ' efficient high-level data structures and a simple but effective' + \
> ' approach to object-oriented programming. Python's elegant syntax' + \

You have an unexscped ' in there.

> ' and dynamic typing, together with its interpreted nature, make it' + \
> ' an ideal language for scripting and rapid application development' + \
> ' in many areas on most platforms. ';


>   transcript
>
> a 0.0680 s,  a 1.2040 s,  a 9.5823 s,  a 81.9688 s,

My times are very nearly linear:

a 0.0280 s,  a 0.2931 s,  a 2.9006 s,  a 29.4318 s,

-- 
Ben.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bringing Order to programming

2019-01-31 Thread Chris Angelico
On Fri, Feb 1, 2019 at 2:00 PM MRAB  wrote:
>
> On 2019-02-01 00:28, Avi Gross wrote:
> > The second variant is to use the newer bytearray data structure very
> > carefully as it is to a first approximation a mutable string. Adding to the
> > end of a new one should be quick. WARNING: I said be careful. A bytearray is
> > more like a list of 8-bit ints. With care you can handle ASCII text.
> >
> If you're replacing anything within the ASCII range, it'll also work for
> UTF-8!

It'll work if you represent the string as UTF-8 bytes, yes. Perhaps it
would be better to represent a string as a sequence of 21-bit integers
instead of 8-bit integers?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Bringing Order to programming

2019-01-31 Thread MRAB

On 2019-02-01 00:28, Avi Gross wrote:

The discussion moved on to debating if an algorithm is O(N) or O(N**2).

For small amounts of text, on fast machines, it really is not worth worrying
about the cost of appending to the end of a growing string resulting in
multiple copies and lots of garbage collection. Many computer textbooks love
to tell you that nothing should be modifiable as a paradigm and endless
copying is good for you since you never change existing data so fewer
mistakes ...

But, for any programmers that happily want to read in entire books and for
some reason then replace all spaces with newlines, may I suggest the
following.

Convert your "text" to/from a list of individual characters. Copy the
non-space characters to the end of an empty list and append a newline when
you see a space. This part should be O(N) as lists have a fast way to append
in constant time. At the end, use str(listname) to do what is needed to get
back a string. Also O(N).

I won't supply the code for obvious reasons but it looks like:

final_list = []
for character in initial_text:
# Add carefully to the end of final_list
final_text = str(final_list)

The second variant is to use the newer bytearray data structure very
carefully as it is to a first approximation a mutable string. Adding to the
end of a new one should be quick. WARNING: I said be careful. A bytearray is
more like a list of 8-bit ints. With care you can handle ASCII text.

If you're replacing anything within the ASCII range, it'll also work for 
UTF-8!

--
https://mail.python.org/mailman/listinfo/python-list


Bringing Order to programming

2019-01-31 Thread Avi Gross
The discussion moved on to debating if an algorithm is O(N) or O(N**2).

For small amounts of text, on fast machines, it really is not worth worrying
about the cost of appending to the end of a growing string resulting in
multiple copies and lots of garbage collection. Many computer textbooks love
to tell you that nothing should be modifiable as a paradigm and endless
copying is good for you since you never change existing data so fewer
mistakes ...

But, for any programmers that happily want to read in entire books and for
some reason then replace all spaces with newlines, may I suggest the
following.

Convert your "text" to/from a list of individual characters. Copy the
non-space characters to the end of an empty list and append a newline when
you see a space. This part should be O(N) as lists have a fast way to append
in constant time. At the end, use str(listname) to do what is needed to get
back a string. Also O(N).

I won't supply the code for obvious reasons but it looks like:

final_list = []
for character in initial_text:
# Add carefully to the end of final_list
final_text = str(final_list)

The second variant is to use the newer bytearray data structure very
carefully as it is to a first approximation a mutable string. Adding to the
end of a new one should be quick. WARNING: I said be careful. A bytearray is
more like a list of 8-bit ints. With care you can handle ASCII text. 





-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread Terry Reedy

On 1/31/2019 3:31 PM, Chupo via Python-list wrote:

In article , Chris
Angelico  says...

There are stupid questions, but I enjoy answering those too. You don't
need to apologize for asking these questions. All you need to do is
ignore the trolls like Rick. In fact, if you abandon Google Groups and
instead read the mailing list python-list@python.org, you can just
leave behind all the people who've been blocked.



Thank you for the tip.

I am in fact not using Google Groups but am accessing comp.lang.python
via nntp:// by using a newsreader.


Then point your newsreader, as I have, to news.gmane.org and subscribe 
to gmane.comp.python.general, which mirrors python-list.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Terry Reedy

On 1/31/2019 1:36 PM, Grant Edwards wrote:

On 2019-01-31, Grant Edwards  wrote:

On 2019-01-31, Terry Reedy  wrote:

On 1/31/2019 11:19 AM, Ian Clark wrote:

text = "The best day of my life!"
output = ''

for i in text:
   if i == ' ':
output +='\n'
   else:
output += i

print(output)



But this is an awful, O(n*n) way to solve an inherently O(n) problem,


How is it O(n^2)?

It loops through the input sequence exactly once.  That looks like
O(n) to me.


Doh!

The 'output +=' operation is also O(n), and it's executed n times.


It is like bubble sort doing n x O(n) operations.  This does not mean 
that O(n*n) is always bad as it may beat O(n*logn) or even O(n) in terms 
of real time when the neglected multiplier and other terms are 
considered*. I regularly write use + to catenate a few, fixed number of 
terms.  But I just read a blogger who used += in a loop like the above 
where there could also be 1000s or more strings to be added together.


* timsort (Tim Peters), used for list.sort and other language sorts, 
uses 'O(n*n)' binary insert sort for 'short' subarrays.  Tim empirically 
selected 64 as the boundary between 'short' and 'long' for Python.  On 
modern CPUs, the O(n*n), shifting part of an array, is done (relatively 
fast) with a single machine instruction.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread DL Neil

On 1/02/19 9:00 AM, Chris Angelico wrote:

On Fri, Feb 1, 2019 at 6:56 AM Chupo via Python-list
 wrote:

In article <67d5c4bc-7212-43d0-b44f-7f22efffa...@googlegroups.com>,
Rick Johnson  says...




I was thought there aren't stupid questions, just stupid answers and I
for sure won't apologize for asking any question. If someone things the
question I asked is stupid they can ignore it. I am not affraid of
losing my reputation by asking a question.



There are stupid questions, but I enjoy answering those too. You don't

...

(TLDR?: the are "stupid questions", here's why, and some ideas with 
which to frame/consider responses)



Many years ago, gulp, decades ago; when I first started-out in 
vocational training, I also thought 'there are no stupid questions, only 
stupid answers'. Possibly I was?am idealistic in other ways too.


Whilst this phrase 'sounds good', is it logical? It seems to assume that 
a questioner can never ask something in a stupid fashion, whilst at the 
same time assuming/insulting a respondent with the opposite assumption. 
(notwithstanding that it can be difficult to find the right words with 
which to phrase a question - particularly someone learning Python's 
concepts. Also, we should never forget that many 'here' are not 
communicating in their primary/home language - thank you for making that 
effort!)



Back when we rode dinosaurs to school, the maxim was "children should be 
seen and not heard". The teacher was 'the sage on the stage' and 
questions had to be invited/were not encouraged - talking to others was 
either "behind the teacher's back" or "cheating", and thus subject to 
discipline (yes, there was such a thing, once upon a time). Today, there 
is a more social approach to learning, where questions, of the teacher 
or of peers are encouraged - and if you'll permit me to disappear into 
cognitive psychology for a moment, it is a much more efficient way to 
learn! However, it also requires that whereas we didn't 'interfere' with 
others' learning by keeping silent, the members of such a 'modern' 
society find new levels of respect for each other, when it is (not) 
acceptable to do such things, etc, etc.


Contrarily, we also live in 'the Internet Age' which includes the rise 
of a sense (?right) of "immediacy". In short: we want it now! Sadly, 
this engenders an apparent motivation to rush 'in' (see also "panic"), 
rather than holding-fire and thinking first - or as the old dinosaur 
used to say "put brain into gear, before mouth into motion"!


I should also mention that the above is very much a description of how 
things are 'in the west' (ie 'western world', 'western culture'). 
Younger colleagues educated in India and China (per example only) tell 
me that their educational modus 'today' is much closer to my own 'back 
then'. Accordingly, until friendships are establish, preparedness to ask 
questions is low - is thought to reveal ignorance, even lack of respect 
of 'teacher'.



There are 'bad questions':

- someone unable to immediately solve a problem, turns to his 
colleague/this list and garbles:

- there may be facts, but are they sufficient?
	- there is often no background to understand the motivation for the 
question
	- there is usually a component of 'how do I fix my solution' cf here is 
the (actual) problem to be solved


- laziness, ie asking someone else to exert effort to save self
- eg no evidence of an attempted solution
- no reference to web or book research

- learning avoidance (even 'destruction'):
	- see current conversation on list where student has clearly said that 
he is dealing with a teacher-directed assignment



So the definition of 'bad question' may boil-down to the motivation of 
the questioner being 'good' or 'bad', rather than the wording itself. 
Why are you asking this question?



Amusingly enough, that's amongst the training given to anyone learning 
training (if you follow): always try to (first) understand why the 
person is asking you this question, then try to answer in similar mode!


- a question asked on-impulse pretty much implies that a direct/complete 
answer will be taken similarly. In which case, it is extremely unlikely 
that the questioner will *learn* from the experience - thus will be 
forced to ask again 'next time'. "Give a man a fish and he eats today. 
Teach a man to fish and he eats every day!" (only an aphorism, sadly not 
literal fact!) Accordingly, 'answering' the original question with 
clarification questions is not a 'silly answer'. Indeed neuroscience 
shows that taking a break from a problem allows the brain to move 'the 
facts' from "working memory" into 'the back of my mind' and/or more 
permanent memory (ie learning); and possibly more important to 
problem-solving, from the logico-cortex into other parts of the brain 
where 'the facts' become associated with "prior knowledge" and other 
components of 'intelligence' may be brought to bear. How often have you 
taken a sh

Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread Chupo via Python-list
In article , 
Rick Johnson  says...
> You know _all_ that


What I mentioned is just a small excerpt of what I know :-)


> yet... you didn't know about the built-in `type()` method?

Exactly :-)

> Well, that's just great. We can only hope you don't try your hand at any 
> mission-critical code. And i suppose when the plane crashes you can always 
> fall back on the "beautiful plumage" of your resume, eh chap?
> 

Now that you are saying that, I thing I should abandon my 150 km/h 
racing quadcopter flight controller project :-O

Especially because my idea was to use PYTHON for analyzing the data 
from onboard black box flash in order to fine tune PIDs. Hahah

LOL :-)
-- 
Let There Be Light
Custom LED driveri prema specifikacijama
http://tinyurl.com/customleddriver

Chupo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread Chupo via Python-list
In article , Chris 
Angelico  says...
> Ah okay. You may want to killfile a few people then, since you're
> using an actual real newsreader and have that capability.
> 

Yes, Gravity has Bozo Bin for that purpose :-) But although I've been 
using newsgroups for 20 years I've never blocked a single person by 
using a filter because it is not hard to just not open certain messages 
posted by known authors. Especially nowadays when post count is so low.
-- 
Let There Be Light
Custom LED driveri prema specifikacijama
http://tinyurl.com/customleddriver

Chupo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread Chupo via Python-list
In article , Chris 
Angelico  says...
> There are stupid questions, but I enjoy answering those too. You don't
> need to apologize for asking these questions. All you need to do is
> ignore the trolls like Rick. In fact, if you abandon Google Groups and
> instead read the mailing list python-list@python.org, you can just
> leave behind all the people who've been blocked.
> 

Thank you for the tip.

I am in fact not using Google Groups but am accessing comp.lang.python 
via nntp:// by using a newsreader.

I think Google Groups destroyed usenet.
-- 
Let There Be Light
Custom LED driveri prema specifikacijama
http://tinyurl.com/customleddriver

Chupo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread Chris Angelico
On Fri, Feb 1, 2019 at 7:36 AM Chupo via Python-list
 wrote:
>
> In article , Chris
> Angelico  says...
> > There are stupid questions, but I enjoy answering those too. You don't
> > need to apologize for asking these questions. All you need to do is
> > ignore the trolls like Rick. In fact, if you abandon Google Groups and
> > instead read the mailing list python-list@python.org, you can just
> > leave behind all the people who've been blocked.
> >
>
> Thank you for the tip.
>
> I am in fact not using Google Groups but am accessing comp.lang.python
> via nntp:// by using a newsreader.

Ah okay. You may want to killfile a few people then, since you're
using an actual real newsreader and have that capability.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread Chupo via Python-list
> I was thought
> 

I meant: 'I was taught'.
-- 
Let There Be Light
Custom LED driveri prema specifikacijama
http://tinyurl.com/customleddriver

Chupo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread Chris Angelico
On Fri, Feb 1, 2019 at 6:56 AM Chupo via Python-list
 wrote:
>
> In article <67d5c4bc-7212-43d0-b44f-7f22efffa...@googlegroups.com>,
> Rick Johnson  says...
>
> 
>
> > I'm impressed! But you're asking basic questions that someone with your 
> > resume should either (1) already know, or (2) be competent enough to find 
> > on their own. Now don't get me wrong. My intention is not to ridicule you. 
> > But, with your resume, you should be embarrassed to ask such basic 
> > questions. You are obviously not an idiot. If you can do what you claim you 
> > can do, then you are intelligent and driven
> person. There are redeemable qualities. Don't waste them. And don't undercut 
> your reputation by appearing to be a hapless rube.
>
>
> I was thought there aren't stupid questions, just stupid answers and I
> for sure won't apologize for asking any question. If someone things the
> question I asked is stupid they can ignore it. I am not affraid of
> losing my reputation by asking a question.
>
>

There are stupid questions, but I enjoy answering those too. You don't
need to apologize for asking these questions. All you need to do is
ignore the trolls like Rick. In fact, if you abandon Google Groups and
instead read the mailing list python-list@python.org, you can just
leave behind all the people who've been blocked.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trying to figure out the data type from the code snippet

2019-01-31 Thread Chupo via Python-list
In article <67d5c4bc-7212-43d0-b44f-7f22efffa...@googlegroups.com>, 
Rick Johnson  says...



> I'm impressed! But you're asking basic questions that someone with your 
> resume should either (1) already know, or (2) be competent enough to find on 
> their own. Now don't get me wrong. My intention is not to ridicule you. But, 
> with your resume, you should be embarrassed to ask such basic questions. You 
> are obviously not an idiot. If you can do what you claim you can do, then you 
> are intelligent and driven 
person. There are redeemable qualities. Don't waste them. And don't undercut 
your reputation by appearing to be a hapless rube.


I was thought there aren't stupid questions, just stupid answers and I 
for sure won't apologize for asking any question. If someone things the 
question I asked is stupid they can ignore it. I am not affraid of 
losing my reputation by asking a question.

 
> Hmm. I don't see anything here that a child couldn't be taught to do.

You failed to see the point of the code snippet I pasted, let me 
explain what was my intention to show with that code:

Since I said I wrote a driver for 3D printer and since there is:

from Printer3D import Head

at the beginning of the code and there is:

hd = Head(layer)

below - from just those two lines you could conclude I wrote Head class 
meaning I *am* aware what object is. And since hd.printLayer() 
obviously does print a layer of the material, that means my 3D printer 
driver is working well. I assumed you could imagine that the driver for 
driving the head of 3D printer is not just a few lines of code, that it 
works in real-time and that it interacts with the hardware.
 
> Your reseme may be impressive... 


What I mentioned is not my resume, I just mentioned what I, knowing 
only Python basics, did using Python. My resume includes:

Embedded devices for industry process control automation (temperature, 
fluid level, time, data from PID controller, ?); VFD control systems with 
complex menu structure, user friendly interface, failsafe and data retention; 
IoT 
applications; multi-channel sound generation; bike computer; remote data 
acquisition 
over RF; data logging; ERP software coding (C#); client&web service sw for 
warehouse 
handheld data acquisition system (SOAP requests), software for CNC machines 
duty 
simplifications and many more

I am an expert on embedded systems design with more than 50,000 lines of C code 
built-in in various working firmwares. I both designed and built many embedded 
electronic devices based on various microcontrollers doing all the production 
stages, 
designing circuit schematics, calculating the elements, designing printed 
circuit boards, 
generating Gerber files according to the manufacturing requirements, soldering 
components (both TH and SMD) and coding&debugging the firmwares. By utilizing 
GCC 
based toolchain and Bare Metal Programming, developing my own libraries and 
optimizing the most critical routines by writing them in assembler I can often 
design the 
devices based on 16 MHz or even just 8 MHz Atmel AVR line of microcontrollers, 
where 
others would resort to using 72 MHz ARM or even more powerful processors. 
Although 
my carefully optimized devices usually outperform the devices based on even 
much 
more powerful hardware, I am using the newest generation of microcontrollers 
such as 
ESP8266 and ESP32 as well. I learnt Z80 assembler when I was 10 and after years 
of 
coding in both Z80 and 6502 assembler it was easy to start using Microchip's 
PIC 
microcontrollers. Later on I switched to Atmel's (now Microchip) 
microcontrollers and to 
the newest ones I mentioned before.

I can start using completely new family of microcontrollers and completely new 
toolchains in a matter of days. I coded all sorts of SPI, I2C, UART, 1-Wire 
etc. and 
custom communication routines, both using the hardware peripherals and/or bit 
banging 
algorithms, hardware/software PWM, efficient debounce algorithms, multitasking 
environments, routines for precise measuring of pulse lengths, complex ISR 
routines 
with carefully calculated T-states (cycles) per pass, DDS algorithms, graphic 
display 
libraries, libraries for communicating with various devices (e.g. NRF24L01+), 
EEPROM 
wear leveling routines and many more. Furthermore, I have a vast experience 
with 
reverse engineering .hex files extracted from microcontrollers which allows me 
to easily 
proof the assembly code generated by the compiler in order to - if necessary - 
rewrite 
the code in a more efficient way, while my deep understanding of serial and 
parallel 
programming protocols, bootloaders, JTAG debugging and inner workings of a 
microcontroller allows me to cope with all kinds of problems that could be met 
while 
developing embedded devices (e.g. noisy environments, black-outs, brown-outs, 
BUS 
contention, contact bounce, ?). Additionally, I have a reasonable knowledge of 
Genetic 
and other AI algorithms (pathfinding, game 

Re: How to replace space in a string with \n

2019-01-31 Thread Neil Cerutti
On 2019-01-31, ^Bart  wrote:
> Hello everybody! :)
>
> I got a text and I should replace every space with \n without to use 
> str.replace, I thought something like this:
>
> text = "The best day of my life!"
>
> space = (' ')
>
> if text.count(' ') in text:
>  space=\n
>
> rightText = text-space
>
>  print(rightText)

Your code resembles Python code, but it isn't close enough for me
to offer reasonable help.

You should figure out how to solve your problem *before* you
start to write code. A paper and pencil will be required!

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Grant Edwards
On 2019-01-31, ^Bart  wrote:
> Hello everybody! :)
>
> I got a text and I should replace every space with \n without to use 
> str.replace, I thought something like this:
>
> text = "The best day of my life!"

[...]

> I should have an output like this:
> The
> best
> day
> of
> my
> life!

Here's a solution. But don't turn it in. You're not supposed to know
how to do this yet, and your instructor will know you copied it from the
internet:

print(''.join('\n' if c == ' ' else c for c in text))

-- 
Grant Edwards   grant.b.edwardsYow! over in west
  at   Philadelphia a puppy is
  gmail.comvomiting ...

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Chris Angelico
On Fri, Feb 1, 2019 at 5:34 AM Grant Edwards  wrote:
>
> On 2019-01-31, Terry Reedy  wrote:
> > On 1/31/2019 11:19 AM, Ian Clark wrote:
> >> text = "The best day of my life!"
> >> output = ''
> >>
> >> for i in text:
> >>   if i == ' ':
> >>output +='\n'
> >>   else:
> >>output += i
> >>
> >> print(output)
>
> > But this is an awful, O(n*n) way to solve an inherently O(n) problem,
>
> How is it O(n^2)?
>
> It loops through the input sequence exactly once.  That looks like
> O(n) to me.
>

Appending onto an immutable string means copying the entire string and
adding the new character.

(CPython does have an optimization that can sometimes improve this
specific case, but in general, this algorithm runs in quadratic time.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Grant Edwards
On 2019-01-31, Grant Edwards  wrote:
> On 2019-01-31, Terry Reedy  wrote:
>> On 1/31/2019 11:19 AM, Ian Clark wrote:
>>> text = "The best day of my life!"
>>> output = ''
>>> 
>>> for i in text:
>>>   if i == ' ':
>>>output +='\n'
>>>   else:
>>>output += i
>>> 
>>> print(output)
>
>> But this is an awful, O(n*n) way to solve an inherently O(n) problem,
>
> How is it O(n^2)?
>
> It loops through the input sequence exactly once.  That looks like
> O(n) to me.

Doh!

The 'output +=' operation is also O(n), and it's executed n times.

-- 
Grant Edwards   grant.b.edwardsYow! I hope something GOOD
  at   came in the mail today so
  gmail.comI have a REASON to live!!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Grant Edwards
On 2019-01-31, Terry Reedy  wrote:
> On 1/31/2019 11:19 AM, Ian Clark wrote:
>> text = "The best day of my life!"
>> output = ''
>> 
>> for i in text:
>>   if i == ' ':
>>output +='\n'
>>   else:
>>output += i
>> 
>> print(output)

> But this is an awful, O(n*n) way to solve an inherently O(n) problem,

How is it O(n^2)?

It loops through the input sequence exactly once.  That looks like
O(n) to me.

-- 
Grant Edwards   grant.b.edwardsYow! Not SENSUOUS ... only
  at   "FROLICSOME" ... and in
  gmail.comneed of DENTAL WORK ... in
   PAIN!!!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Terry Reedy

On 1/31/2019 11:19 AM, Ian Clark wrote:

text = "The best day of my life!"
output = ''

for i in text:
  if i == ' ':
   output +='\n'
  else:
   output += i

print(output)

throwing my hat in the ring, not only is it .replace free it is entirely
method free


But this is an awful, O(n*n) way to solve an inherently O(n) problem, 
which I think should not be taught to beginners unless they are 
simultaneously taught to never do this for indefinitely large n.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


RE: How to replace space in a string with \n

2019-01-31 Thread Avi Gross
It is amazing to watch what happens when a fairly simple question is asked
to see how people answer.

In an effort not to ramble, I will summarize my thoughts. The student wanted
to know how to solve a problem using only what they already should know and
that specifically they should not use a method. In effect, they are being
asked to write the kind of code that might be used to make such a method.

There were many answers including some that absurdly suggested even more
advanced methods they should not know. Frankly, the question belongs more in
the sister list for tutoring and even there, the goal is NOT to supply an
answer but point out flaws in code provided as an attempt or suggest an
outline of a method and let the student fill it out and learn.

This is not only a public forum but one that is searchable indefinitely into
the future. Providing a full-blown answer not only hands a solution to one
student but to their classmates and any future takers.

I note another poster asking questions turns out to be not a student but
someone quite advanced who likes to learn just in time as they search for
what is needed. They require a very different approach and can learn well
from being handed a more detailed solution they can interpolate into their
project. 

So, how do you replace? I think a loop answer is probably best for this
student. For the second type of questioner, many of the others would be
great including suggesting they just use replace as there is nothing wrong
with that!

NOTE: It is great when we have an exact set of requirements. I note that the
requirement here might not require making a new string at all. If you just
need to PRINT the words on multiple lines, one solution is to call "print"
on each character in the loop using the appropriate method to suppress
printing a newline except when you see a blank.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Ian Clark
text = "The best day of my life!"
output = ''

for i in text:
 if i == ' ':
  output +='\n'
 else:
  output += i

print(output)

throwing my hat in the ring, not only is it .replace free it is entirely
method free

On Thu, Jan 31, 2019 at 3:41 AM ^Bart  wrote:

> [Solved by myself and I'm happy!!! :)]
>
> text = "The best day of my life!"
>
> space = text[3]
>
> print (text.replace(space, "\n"))
>
> [Like what I said in another message, in the afternoon I'll ask to the
> teacher if for this exercise we're able to use .replace]
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread ^Bart

[Solved by myself and I'm happy!!! :)]

text = "The best day of my life!"

space = text[3]

print (text.replace(space, "\n"))

[Like what I said in another message, in the afternoon I'll ask to the 
teacher if for this exercise we're able to use .replace]

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Michael Poeltl
hi ^Bert,

I've just thought that you don't like to use text.replace(' ', '\n'), and so I 
came up with another way to get the job done.

So it was part of a "school-test" - uiuitststs ;-)

follow the hint from Peter then, and inside *your* for-loop ask yourself, how 
to inspect the value of c in a loop and what to do *if* the value of c was ' ' .

as mentioned, a string is immuteable, so you cannot change it *inplace* - you 
have to build a new str-object (has a new object-id the starting with an empty 
string say

newtext = ''
and with each loop over your original text you add one character like

newtext = newtext+c

and only if c has a value of ' ', then you add a different value like '\n'

well, now you should try to understand peters for-loop, and then you should try 
to combine what you have learned with the if-statement within the for(-loop) 
block

happy learning the python-language! It's a great one, this I can promise you!
regards
Michael

* Peter Otten <__pete...@web.de> [2019-01-31 11:15]:
> ^Bart wrote:
> 
> >> Why?
> > 
> > It's a school test, now we should use just what we studied, if than,
> > else, sequences, etc.!
> > 
> > ^Bart
> 
> Hint: you can iterate over the characters of a string
> 
> >>> for c in "hello":
> ... print(c)
> ... 
> h
> e
> l
> l
> o
> 
> 
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.6.1, on linux mint 17.3 (rose)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Chris Angelico
On Thu, Jan 31, 2019 at 9:56 PM ^Bart  wrote:
>
> >You coulde use »sub« from the module »re«, then.
> >(The Python Library Reference, Release 3.8.0a0 -
> >6.2 re - Regular expression operations)
>
> We're using 3.7.2 :\
>

Don't worry about that difference - 3.8 is only minorly different from 3.7.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Antoon Pardon
On 31/01/19 11:47, ^Bart wrote:
>>    . A correct answer to the exercise would be:
>>
>> |You cannot replace a space with \n in a string,
>> |because strings are immutable in Python.
>
> Yes, I thought in a wrong way! :)
>
Well maybe you can turn the string into a list of characters. Then
replace the spaces with newlines and finaly turn the list into a string
again. -- Antoon.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread ^Bart

No it is not the proper way of a school test to copy what others provided.


You're right but I need just to understand what tools I should use, it 
could be nice if the teacher says something like "use just these three 
tools to solve this problem" or "you don't need to use these other tools 
to do it!"


I hope you understood what I mean...

^Bart

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread ^Bart

   You coulde use »sub« from the module »re«, then.
   (The Python Library Reference, Release 3.8.0a0 -
   6.2 re - Regular expression operations)


We're using 3.7.2 :\


   Otherwise,

   Write a loop that takes the first character from
   the source and appends it to a new string until
   there is no more character left in the source.

   You now should have written a loop that copies
   the string character by character.

   Then it is easy to modify the loop a little bit
   to complete the exercise.


I'll ask it to the teacher this afternoon, thanks for your reply! :)

^Bart
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread ^Bart

   . A correct answer to the exercise would be:

|You cannot replace a space with \n in a string,
|because strings are immutable in Python.


Yes, I thought in a wrong way! :)

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread ^Bart

Il 31/01/19 10:34, Michael Poeltl ha scritto:

hi,
Maybe this is a proper way to do what you'd liked to achieve


text = "The best day of my life!"
newtext = '\n'.join( text.split() )
print(newtext)

The
best
day
of
my
life!




yours
Michael


Thanks Michael, I'll ask to my teacher in the afternoon if he has the 
same idea, you know when you start a new language you should solve 
problems just with few things, when your mind understood how the 
language works you can use every tools of this language! :)


^Bart
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread ^Bart

Have you even tried to run this?


No, it doesn't run, it's just a personal idea! :)


I don't think this does what you think it does.

text.count(' ') will return 5, an integer. So you are testing if 5 is in text. 
But since
5 is an integer that will raise a TypeError.


Yes, I understood this is wrong!


rightText = text-space



Where does text-space come from?


I thought to use (text) - (space), space is " " but I should replace in 
text what I said in the variable is space.


I know there are a lot o solutions but this afternoon I'll ask to the 
teacher what we should do to do it!


Thank you very much for your reply! :)
^Bart
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Antoon Pardon
On 31/01/19 10:37, Michael Poeltl wrote:
> hi,
>
> ^Bart  ended in a Mail-Delivery...
> so I send it ONLY to the python-list
>
> ^Bert, a proper way to do what you'd liked to achieve is the following:

No it is not the proper way of a school test to copy what others provided.

-- 
Antoon.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Antoon Pardon
On 31/01/19 10:18, ^Bart wrote:
> Hello everybody! :)
>
> I got a text and I should replace every space with \n without to use
> str.replace, I thought something like this:

Have you even tried to run this?

>
> text = "The best day of my life!"
>
> space = (' ')
>
> if text.count(' ') in text:
>     space=\n

I don't think this does what you think it does.

text.count(' ') will return 5, an integer. So you are testing if 5 is in text. 
But since
5 is an integer that will raise a TypeError.

>
> rightText = text-space


Where does text-space come from?

-- 
Antoon.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Peter Otten
^Bart wrote:

>> Why?
> 
> It's a school test, now we should use just what we studied, if than,
> else, sequences, etc.!
> 
> ^Bart

Hint: you can iterate over the characters of a string

>>> for c in "hello":
... print(c)
... 
h
e
l
l
o




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Michael Poeltl
hi,

^Bart  ended in a Mail-Delivery...
so I send it ONLY to the python-list

^Bert, a proper way to do what you'd liked to achieve is the following:

>>> text = "The best day of my life!"
>>> newtext = '\n'.join( text.split() )
>>> print(newtext)
The
best
day
of
my
life!
>>>

regards
Michael

* ^Bart  [2019-01-31 10:22]:
> Hello everybody! :)
> 
> I got a text and I should replace every space with \n without to use
> str.replace, I thought something like this:
> 
> text = "The best day of my life!"
> 
> space = (' ')
> 
> if text.count(' ') in text:
> space=\n
> 
> rightText = text-space
> 
> print(rightText)
> 
> I should have an output like this:
> The
> best
> day
> of
> my
> life!
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.6.1, on linux mint 17.3 (rose)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Michael Poeltl
hi,
Maybe this is a proper way to do what you'd liked to achieve

>>> text = "The best day of my life!"
>>> newtext = '\n'.join( text.split() )
>>> print(newtext)
The
best
day
of
my
life!
>>>

yours
Michael

* ^Bart  [2019-01-31 10:22]:
> Hello everybody! :)
> 
> I got a text and I should replace every space with \n without to use
> str.replace, I thought something like this:
> 
> text = "The best day of my life!"
> 
> space = (' ')
> 
> if text.count(' ') in text:
> space=\n
> 
> rightText = text-space
> 
> print(rightText)
> 
> I should have an output like this:
> The
> best
> day
> of
> my
> life!
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.6.1, on linux mint 17.3 (rose)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Michael Poeltl
maybe this is an alternative way to get your wished result.

>>> text = "The best day of my life!"
>>> newtext = '\n'.join( text.split() )
>>> print(newtext)
The
best
day
of
my
life!
>>>

yours
Michael
* ^Bart  [2019-01-31 10:22]:
> Hello everybody! :)
> 
> I got a text and I should replace every space with \n without to use
> str.replace, I thought something like this:
> 
> text = "The best day of my life!"
> 
> space = (' ')
> 
> if text.count(' ') in text:
> space=\n
> 
> rightText = text-space
> 
> print(rightText)
> 
> I should have an output like this:
> The
> best
> day
> of
> my
> life!
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
  Michael Poeltl 
  Computational Materials Physics at University
  Wien, Sensengasse 8/12, A-1090 Wien, AUSTRIA
  http://cmp.univie.ac.at/
  http://homepage.univie.ac.at/michael.poeltl/
  using elinks-0.12, mutt-1.5.21, and vim-7.4,
  with python-3.6.1, on linux mint 17.3 (rose)   :-)
  fon: +43-1-4277-51409

  "Lehrend lernen wir!"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread ^Bart

Why?


It's a school test, now we should use just what we studied, if than, 
else, sequences, etc.!


^Bart
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to replace space in a string with \n

2019-01-31 Thread Alister via Python-list
On Thu, 31 Jan 2019 10:18:20 +0100, ^Bart wrote:

> Hello everybody! :)
> 
> I got a text and I should replace every space with \n without to use
> str.replace,

Why?

> I thought something like this:
> 
> text = "The best day of my life!"
> 
> space = (' ')
> 
> if text.count(' ') in text:
>  space=\n
> 
> rightText = text-space
> 
>  print(rightText)
> 
> I should have an output like this:
> The best day of my life!





-- 
There is nothing new except what has been forgotten.
-- Marie Antoinette
-- 
https://mail.python.org/mailman/listinfo/python-list


EPS: Announcing the Guido van Rossum Core Developer Grant

2019-01-31 Thread M.-A. Lemburg
At the last General Assembly of the EuroPython Society (EPS) at
EuroPython 2018 in Edinburgh, we voted on a new grant program we want
to put in place for future EuroPython conferences.

We all love Python and this is one of the main reasons we are putting
on EuroPython year after year, serving the "cast of thousands" which
support Python. But we also believe it is important to give something
back to the main team of developers who have contributed lots of their
time and energy to make Python happen: the Python Core Developers.

This group is small, works countless hours, often in their free time
and often close to burnout due to not enough new core developers
joining the team.

Free Tickets for Python Core Developers
---

To help with growing the team, putting it more into the spotlight and
give them a place to meet, demonstrate their work and a stage to
invite new developers, we decided to give Python Core Developers free
entry to future EuroPython conferences, starting with EuroPython 2019
in Basel, Switzerland

In recognition of Guido’s almost 20 years of leading this team, and
with his permission, we have named the grant “Guido van Rossum Core
Developer Grant”.

Details of the grant program are available on our core grant page:

https://www.europython-society.org/core-grant

PS: If you are a core developer and want to organize a workshop,
language summit or similar event at EuroPython 2019, please get in
touch with our program workgroup (prog...@europython.eu) soon, so that
we can arrange rooms, slots, etc.

PPS: If you want to become a core developer, please have a look at the
Python Dev Guide:

https://devguide.python.org/coredev/



Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://www.europython-society.org/post/182445627020/announcing-the-guido-van-rossum-core-developer

Tweet:

https://twitter.com/europythons/status/1090901995635073024


Enjoy,
--
EuroPython Society
https://ep2019.europython.eu/
https://www.europython-society.org/

-- 
https://mail.python.org/mailman/listinfo/python-list


How to replace space in a string with \n

2019-01-31 Thread ^Bart

Hello everybody! :)

I got a text and I should replace every space with \n without to use 
str.replace, I thought something like this:


text = "The best day of my life!"

space = (' ')

if text.count(' ') in text:
space=\n

rightText = text-space

print(rightText)

I should have an output like this:
The
best
day
of
my
life!

--
https://mail.python.org/mailman/listinfo/python-list