Skip to content

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.

License

Notifications You must be signed in to change notification settings

hygull/pyrandocs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyrandocs

String formatting

>>> 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 3.5.2

def 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

>>> 
>>> 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)]
>>> 
>>> 
>>> 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

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published