Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Too Stupid to Code
#15
One angle to look at it: to program one uses programming language. As with spoken language it not so much about what courses you attend but how much you speak in this language. In order to master any language on must practice/use it.

At the end of the day programming is an idea in spoken language translated into programming language. Python makes this translation relatively easy, but as with spoken language - if you don't have anything to say then there is nothing to translate.

Simplified example follows. Let's have task to find even numbers. We have list:

lst = [2, 1, 5, 6, 7, 10]
How would we do it with paper and pencil (how we describe it in spoken language) - 'take one number at a time, check if it's even, if so keep it'. How to translate it into Python?

'take one number at a time' -> for num in lst
'check if it's even' -> num % 2 == 0
'keep it' -> one can either print it out, add to list or use list comprehension:

>>> for num in lst:
...     if num % 2 == 0:
...         print(num)
... 
2
6
10
>>> evens = []
>>> for num in lst:
...     if num % 2 == 0:
...         evens.append(num)
... 
>>> evens
[2, 6, 10]
>>> [num for num in lst if num % 2 == 0]
[2, 6, 10]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Too Stupid to Code - by RazerNismo - Oct-02-2019, 07:01 AM
RE: Too Stupid to Code - by Axel_Erfurt - Oct-02-2019, 08:05 AM
RE: Too Stupid to Code - by RazerNismo - Oct-02-2019, 08:14 AM
RE: Too Stupid to Code - by metulburr - Oct-02-2019, 10:20 AM
RE: Too Stupid to Code - by RazerNismo - Oct-02-2019, 11:15 AM
RE: Too Stupid to Code - by metulburr - Oct-02-2019, 12:28 PM
RE: Too Stupid to Code - by ichabod801 - Oct-02-2019, 01:28 PM
RE: Too Stupid to Code - by metulburr - Oct-02-2019, 06:45 PM
RE: Too Stupid to Code - by eldemonionegro - Oct-03-2019, 07:21 AM
RE: Too Stupid to Code - by wavic - Oct-03-2019, 02:47 PM
RE: Too Stupid to Code - by Truman - Oct-03-2019, 08:50 PM
RE: Too Stupid to Code - by wavic - Oct-03-2019, 11:09 PM
RE: Too Stupid to Code - by allusernametaken - Oct-04-2019, 02:41 AM
RE: Too Stupid to Code - by szbeco - Nov-05-2019, 03:40 PM
RE: Too Stupid to Code - by perfringo - Nov-06-2019, 07:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Stupid Bots ichabod801 0 1,904 Oct-23-2019, 07:46 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020