Sep-13-2018, 02:26 PM
(Sep-13-2018, 02:05 PM)Drone4four Wrote:mystring = "Secret agents are super good at staying hidden." mystring.split()
Strings are immutable objects - meaning that they cannot be changed "in-place". You essentially create a temporary list object without assigning the result - so that list is lost
(Sep-13-2018, 02:05 PM)Drone4four Wrote:Result ofcounted_string = len(mystring) int(counted_string)
len
function is integer - and the second line again does nothing(Sep-13-2018, 02:05 PM)Drone4four Wrote:for i in counted_string: if i %2 == 0: print(i)
In Python, you iterate over lists directly; if you need index - you use
enumerate
function; if you want to iterate over range of values - you use range
function (just to explain your mistake, don't need it here)This video is highly recommended for those learning how to loop in Python
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.