Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,205,837 members, 7,993,915 topics. Date: Monday, 04 November 2024 at 09:42 PM

Common good python programming practices you should know - Programming (5) - Nairaland

Nairaland Forum / Science/Technology / Programming / Common good python programming practices you should know (13552 Views)

A Thread For Tutorial On Python Programming / A Very Good Python Programmer Needed Asap / Recommend A Good Python Data Mining Book (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (Reply) (Go Down)

Re: Common good python programming practices you should know by gbolly1151(m): 5:14pm On May 29, 2020
DONT HARDCODE SPLIT() FUNCTION

Assuming full name is seperated by space
e.g 'john smith', 'issac newton' and you want to split to
firstname and lastname

fullname = 'john smith'
#avoid this
name= fullname.split(' ')
firstname = name[0]
lastname = name[1]
print(firstname, lastname)

#pythonic way
firstname, lastname = fullname.split(' ')
print(firstname,lastname)
Re: Common good python programming practices you should know by gbolly1151(m): 10:23am On Jun 03, 2020
UNDERSTAND isinstance() METHOD USING A SIMPLE QUESTION

if someone ask you
"is mr.A from Nigeria?"

the reply is either yes or No i.e True or False

that is the same question you are asking whenever isinstance() method is invoked

"Is object A from class Z?"

e.g isinstance(1,int)
is the same as asking, "is 1 from int?" in which the answer is True
Re: Common good python programming practices you should know by iCode2: 1:26pm On Jun 03, 2020
For this code:
text = input('Enter a string: ')
for i in range(len(text)):
if text[i] == a:
print(i, end=',')


If i type in 'amalgamate', I'll get the following output: 0,2,5,7,

Question: How can I discard that comma after 7?
Re: Common good python programming practices you should know by Should: 7:17pm On Jun 03, 2020
iCode2:
For this code:
text = input('Enter a string: ')
for i in range(len(text)):
if text[i] == a:
print(i, end=',')


If i type in 'amalgamate', I'll get the following output: 0,2,5,7,

Question: How can I discard that comma after 7?
help me put myself together, I'm going mad already..
Help a Believer grin

Re: Common good python programming practices you should know by gbolly1151(m): 7:49pm On Jun 03, 2020
iCode2:
For this code:
text = input('Enter a string: ')
for i in range(len(text)):
if text[i] == a:
print(i, end=',')


If i type in 'amalgamate', I'll get the following output: 0,2,5,7,

Question: How can I discard that comma after 7?

Just seeing this will check
Re: Common good python programming practices you should know by iCode2: 7:59pm On Jun 03, 2020
Should:

help me put myself together, I'm going mad already..
Help a Believer grin
Hmmm I don't understand that screenshot
gbolly1151:


Just seeing this will check
Okay boss
Re: Common good python programming practices you should know by gbolly1151(m): 8:48pm On Jun 03, 2020
iCode2:
For this code:
text = input('Enter a string: ')
for i in range(len(text)):
if text[i] == a:
print(i, end=',')


If i type in 'amalgamate', I'll get the following output: 0,2,5,7,

Question: How can I discard that comma after 7?

This my solution might not be best algorithm but it solve it


text = 'amalgamate'
stop=text.rfind('a')
for i in range(len(text)):
if text[i] == 'a':
if i != stop:
print(i,end=',')
else:print(i,end='.')
Re: Common good python programming practices you should know by gbolly1151(m): 8:55pm On Jun 03, 2020
iCode2:
Hmmm I don't understand that screenshot
You are trying to access an invalid command
Re: Common good python programming practices you should know by iCode2: 11:44pm On Jun 03, 2020
gbolly1151:


This my solution might not be best algorithm but it solve it


text = 'amalgamate'
stop=text.rfind('a')
for i in range(len(text)):
if text[i] == 'a':
if i != stop:
print(i,end=',')
else:print(i,end='.')


You're good, man.

1 Like

Re: Common good python programming practices you should know by Predstan: 12:22am On Jun 04, 2020
i wrote a sparseMatrix ADT implementation. But i am trying to figure out better way to complete the __mul__ implementation. Would you be kind enough to check if there is a better way. Its a long code and works perfectly though but the time-complexity of the __mul__ implementation seems very long.

Here i have the link to the complete code on Github: https://github.com/Predstan/Algorithm-and-Data-Structure/blob/master/ch4/sparseMatrix.py
Re: Common good python programming practices you should know by markwilliam0510(m): 2:43am On Jun 04, 2020
Python is gaining popularity on the web as well as mobile app development due to its robust, powerful, interactive programming language that is easy to learn and reduces development time. Highly interactive, cross-platform support, object-oriented, open-source are some of the highlighting features of Python that lure developers to adapt it.

Python has a wide range of frameworks to offer to make things easier for developers. They are mainly categorized into,

Full Stack Python Framework

1. Django
2. TurboGears
3. Web2py


Non-Full Stack Python Frameworks

1. CherryPy
2. Flask
3. Bottle

Source: https://www.openxcell.com/blog/python-frameworks/

1 Like

Re: Common good python programming practices you should know by gbolly1151(m): 9:27am On Jun 04, 2020
iCode2:
You're good, man.
Glad it work
Re: Common good python programming practices you should know by gbolly1151(m): 9:30am On Jun 04, 2020
Predstan:
i wrote a sparseMatrix ADT implementation. But i am trying to figure out better way to complete the __mul__ implementation. Would you be kind enough to check if there is a better way. Its a long code and works perfectly though but the time-complexity of the __mul__ implementation seems very long.

Here i have the link to the complete code on Github: https://github.com/Predstan/Algorithm-and-Data-Structure/blob/master/ch4/sparseMatrix.py

Will check
Re: Common good python programming practices you should know by gbolly1151(m): 11:40am On Jun 04, 2020
Predstan:
i wrote a sparseMatrix ADT implementation. But i am trying to figure out better way to complete the __mul__ implementation. Would you be kind enough to check if there is a better way. Its a long code and works perfectly though but the time-complexity of the __mul__ implementation seems very long.

Here i have the link to the complete code on Github: https://github.com/Predstan/Algorithm-and-Data-Structure/blob/master/ch4/sparseMatrix.py


Can you give worked example of matrix multiplication output you want, because only dot product i can remember now....dont mind me oo
Re: Common good python programming practices you should know by Predstan: 3:57pm On Jun 04, 2020
gbolly1151:


Can you give worked example of matrix multiplication output you want, because only dot product i can remember now....dont mind me oo

Its a sparse Matrix with several Zero elements. So i used a List for the elements(non zero) in the Matrix and another class to store the row number, col number and value. So the zero elements does not accupy any space in the ADT.
To Multiply two matrices, we first calculate transpose of the second matrix to simplify our comparisons and maintain the sorted order. So, the resultant matrix is obtained by traversing through the entire length of both matrices and summing the appropriate multiplied values.
Any row value equal to x in the first matrix and row value equal to y in the second matrix (transposed one) will contribute towards result[x][y]. This is obtained by multiplying all such elements having col value in both matrices and adding only those with the row as x in first matrix and row as y in the second transposed matrix to get the result[x][y].
Re: Common good python programming practices you should know by gbolly1151(m): 9:40pm On Jun 04, 2020
Predstan:


Its a sparse Matrix with several Zero elements. So i used a List for the elements(non zero) in the Matrix and another class to store the row number, col number and value. So the zero elements does not accupy any space in the ADT.
To Multiply two matrices, we first calculate transpose of the second matrix to simplify our comparisons and maintain the sorted order. So, the resultant matrix is obtained by traversing through the entire length of both matrices and summing the appropriate multiplied values.
Any row value equal to x in the first matrix and row value equal to y in the second matrix (transposed one) will contribute towards result[x][y]. This is obtained by multiplying all such elements having col value in both matrices and adding only those with the row as x in first matrix and row as y in the second transposed matrix to get the result[x][y].

Storing rows using nested list would have been easy...right now,i haven't think what best algorithm will be better.
Re: Common good python programming practices you should know by Should: 3:00am On Jun 05, 2020
gbolly1151:

You are trying to access an invalid command
Pls, how do I make the command valid?
Re: Common good python programming practices you should know by gbolly1151(m): 7:41am On Jun 05, 2020
Should:
Pls, how do I make the command valid?
What do you want to achieve ?
Re: Common good python programming practices you should know by Should: 12:55pm On Jun 05, 2020
Firstly, I'm totally a newbie on programming.
my aim is to get soaked in everything concerning python and other important language..
goal; Cybersecurity, intend using it compliment myself as a Dss agent...

1 Like

Re: Common good python programming practices you should know by gbolly1151(m): 1:36pm On Jun 05, 2020
Should:
Firstly, I'm totally a newbie on programming.
my aim is to get soaked in everything concerning python and other important language..
goal; Cybersecurity, intend using it compliment myself as a Dss agent...
That is good...python is a great way to start ethical hacking, you can pick up book on google and videos then build yourself up
Re: Common good python programming practices you should know by Should: 2:46pm On Jun 05, 2020
gbolly1151:

That is good...python is a great way to start ethical hacking, you can pick up book on google and videos then build yourself up
please, kindly outline necessary things and best step to be taken..
I've got nothing on ground, but I've made up my mind for perfection concerning python..
Finance isn't the issue, vivid explanation is...
Re: Common good python programming practices you should know by gbolly1151(m): 2:57pm On Jun 05, 2020
Should:
please, kindly outline necessary things and best step to be taken..
I've got nothing on ground, but I've made up my mind for perfection concerning python..
Finance isn't the issue, vivid explanation is...

>>>start with python basic,solve questions along the line
>>>socket programming using python
>>>start reading basic ethical hacking,understand the theory
>>>test your skill with practical
Re: Common good python programming practices you should know by Should: 3:51pm On Jun 05, 2020
gbolly1151:


>>>start with python basic,solve questions along the line
>>>socket programming using python
>>>start reading basic ethical hacking,understand the theory
>>>test your skill with practical
Gratitudes!
However, I hope you wouldn't mind if I make you my personal superior, whom to fall back to, in terms of correction...
PS: Seanwilliam, what's your update?
felt like informing you, so we could learn together and on our own..
Re: Common good python programming practices you should know by gbolly1151(m): 5:17pm On Jun 05, 2020
Should:
Gratitudes!
However, I hope you wouldn't mind if I make you my personal superior, whom to fall back to, in terms of correction...
PS: Seanwilliam, what's your update?
felt like informing you, so we could learn together and on our own..
You can reach me on WhatsApp 07060435624

1 Like

Re: Common good python programming practices you should know by seanwilliam(m): 7:42pm On Jun 05, 2020
Should:
Gratitudes!
However, I hope you wouldn't mind if I make you my personal superior, whom to fall back to, in terms of correction...
PS: Sea.nwilliam, what's your update?
felt like informing you, so we could learn together and on our own..
are you refering to me in the bolded?
Re: Common good python programming practices you should know by emilfischer(m): 10:23pm On Jun 05, 2020
Buy quality UK used laptops delivered to your doorstep.
Re: Common good python programming practices you should know by Should: 3:07am On Jun 06, 2020
seanwilliam:
are you refering to me in the bolded?
nope!
Re: Common good python programming practices you should know by Should: 3:09am On Jun 06, 2020
gbolly1151:

You can reach me on WhatsApp 07060435624
lmao
this is what I've been awake for...
with this pace, I'd probably be killing Artificial Intelligence(AI) by nxt week!.. grin grin

1 Like

Re: Common good python programming practices you should know by Predstan: 4:38am On Jun 06, 2020
smiley
Should:
lmao
this is what I've been awake for...
with this pace, I'd probably be killing Artificial Intelligence(AI) by nxt week!.. grin grin

Lol. No small thing
Re: Common good python programming practices you should know by gbolly1151(m): 10:05am On Jun 06, 2020
Should:
lmao
this is what I've been awake for...
with this pace, I'd probably be killing Artificial Intelligence(AI) by nxt week!.. grin grin

Lolz....small small sir,a step at a time

(1) (2) (3) (4) (5) (6) (7) (8) (Reply)

In What Order Did You Learn Your Languages? / Javascript Study Group / What Is The Average Salary Of A Php Programmer In Lagos

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 46
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.