Python Principles (@PyPrinciples) header
Python Principles (@PyPrinciples) profile picture

Learn #Python programming from scratch through practical exercises.

Joined December 2018
Photo by Python Principles (@PyPrinciples)Photo by Python Principles (@PyPrinciples)Photo by Python Principles (@PyPrinciples)Photo by Python Principles (@PyPrinciples)Photo by Python Principles (@PyPrinciples)Photo by Python Principles (@PyPrinciples)Photo by Python Principles (@PyPrinciples)Photo by Python Principles (@PyPrinciples)
Python Principles retweeted
Hey, that's a neat #python trick!
9
66
6
392
Python Principles retweeted
In #Python you can easily create a dict of two sequences using the zip builtin >>> names = 'bob julian tim sara'.split() >>> ages = '11 22 33 44'.split() >>> dict(zip(names, ages)) {'bob': '11', 'julian': '22', 'tim': '33', 'sara': '44'} - via @pybites 🐍
1
15
31
#pythontip from @singhjayp: Use shlex.split() to get shell-like splitting: >>> import re >>> re.split('\s', "this is 'my string'") ['this', 'is', "'my", "string'"] >>> import shlex >>> shlex.split("this is 'my string'") ['this', 'is', 'my string'] teapawt.org/singhjayp/status/10809…
Replying to @python_tip
@python_tip Python standard library's shlex.split function can be used to split the string while preserving the sub-strings in single/double quotes (phrases), unlike str.split where all the strings are separated including the phrases. Here is an example to show the difference:
#python lists have the count() method that returns the number of occurrences of an element: >>> lst = [1, 1, 2, 3, 4, 5, 1, 3, 3, 3, 7, 9, 3] >>> lst.count(2) 1 Most common item: >>> max(lst, key=lst.count) 3
3
32
2
143
#pythontip from @singhjayp: Use difflib.SequenceMatcher to compare strings. docs.python.org/3/library/di… Example:
18
68
** How to write Beautiful Python Code ** realpython.com/python-pep8/
8
11
Python Principles retweeted
How to Send Emails with Python smtplib pybit.es/python-smtplib.html… #Python – at Sydney, New South Wales
15
51