https://github.com/hygull/pyrandocs
A repository (pyrandocs i.e. Python's v2/v3 random documents/files) containing different Python v2/v3 based resources (files/documents etc.) from random topics. A project to try different Python's features.
https://github.com/hygull/pyrandocs
base64 beautifulsoup class exception-handling hashlib json jwt-authentication loops matplotlib nltk numpy pandas python2 python27 python3 requests searching time-complexity urllib urllib2
Last synced: about 1 month ago
JSON representation
A repository (pyrandocs i.e. Python's v2/v3 random documents/files) containing different Python v2/v3 based resources (files/documents etc.) from random topics. A project to try different Python's features.
- Host: GitHub
- URL: https://github.com/hygull/pyrandocs
- Owner: hygull
- License: mit
- Created: 2019-02-02T05:24:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-10T10:34:23.000Z (about 6 years ago)
- Last Synced: 2025-01-22T17:13:42.741Z (3 months ago)
- Topics: base64, beautifulsoup, class, exception-handling, hashlib, json, jwt-authentication, loops, matplotlib, nltk, numpy, pandas, python2, python27, python3, requests, searching, time-complexity, urllib, urllib2
- Language: Python
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyrandocs
String formatting
```bash
>>> d = {
... "complex": 5+6j,
... "int": 1729,
... "float": 3.14,
... "string": "Bangalore",
... "list": [1, 2, 3, 4, -7, 0],
... "tuple": (4,),
... "dictionary": {'fullname': 'Rishikesh Agrawani', 'active': True}
... }
>>>
>>> for key, value in d.items():
... print('{0:10s} : %s'.format(key) % (value))
...
string : Bangalore
dictionary : {'active': True, 'fullname': 'Rishikesh Agrawani'}
tuple : 4
int : 1729
float : 3.14
list : [1, 2, 3, 4, -7, 0]
complex : (5+6j)
>>>
```Stackoverflow - a solution to a problem in a simple way / no use of advanced Python concepts
> https://stackoverflow.com/a/54500843/6615163
>
> You can try it online at https://rextester.com/ISE37337```python
# python 3.5.2def get_count():
n = int(input())
for i in range(n):
s = input().strip()
if not i:
l = list(set(s))
else:
i = 0
while l and i < len(l) - 1:
ch = l[i]
if not ch in s:
l.remove(ch)
else:
i += 1
return len(l)
count = get_count()
print(count) # 2
```List and range() based problem's solution
> https://stackoverflow.com/questions/54505461/how-to-print-out-elements-from-the-list-that-have-the-difference-of-2
```python
>>>
>>> l = [1, 7, 12, 14, 22, 24, 29, 31, 39, 45, 77, 79, 85, 100]
>>> output = [(l[i], l[j]) for i in range(len(l) - 1) for j in range(i + 1, len(l)) if abs(l[i] - l[j]) == 2]
>>> output
[(12, 14), (22, 24), (29, 31), (77, 79)]
>>>
``````python
>>>
>>> l = [1, 7, 12, 14, 22, 24, 29, 31, 39, 45, 77, 79, 85, 100]
>>>
>>> n = len(l) - 1
>>> output = [(l[i], l[i + 1]) for i in range(0, n, 2) if abs(l[i] - l[i + 1]) == 2]
>>> output
[(12, 14), (22, 24), (29, 31), (77, 79)]
>>>
>>> s = '\n'.join([str(output[i][0]) + ', ' + str(output[i][1]) for i in range(len(output))])
>>> print(s)
12, 14
22, 24
29, 31
77, 79
>>>
```References
+ [How to get a list of class attributes in Python](https://www.blog.pythonlibrary.org/2013/01/11/how-to-get-a-list-of-class-attributes/)
+ [List attributes of an object](https://stackoverflow.com/questions/2675028/list-attributes-of-an-object)
+ [datetime, date, time](https://www.programiz.com/python-programming/datetime#example-difference-date)