Giter VIP home page Giter VIP logo

pytricks's Issues

structure collection

At first I want to thank all of you for your help, didn't expect this to become that big :).

All those contributions lead to fact that we need some kind of structuring.
When I enter this repo I feel a little bit overwhelmed with this amount of files.

The question that raises is "What's the right way?". Order them by data types, differentiate between function, performance and readability tricks, etc.. Maybe you guys even decide, that we should leave it as it is.

Feel free to add your opinion :)

New Trick: judge an object in a list of tuple

#! /usr/bin/env python
'''there is a list of tuple, and if you want to judge an object in this list by an elegant way, then...'''

from more_itertools import flatten     # pip install more_itertools

types = [('E', 'I'), ('S', 'N'), ('T', 'F'), ('J', 'P')]

if __name__ == '__main__':    
    assert 'E' in flatten(types)
    assert 'X' in flatten(types)

Add a reversestring.py file

I've made a pull request - #73.

Thought it would be worth an issue to go along side in case it warranted a discussion.

As stated in the pull request:

I think we could justify having a separate file from reverselist for reversing strings and ints.

Some newbies don't have the conceptual leap from slicing lists to slicing strings.

Other possibility is to merge the two into a reverseiterable.py but I feel this is less explicit than two separate files.

patternify

traditional way

'''
Printing the pattern
*
**
***
****
'''
for i in range(1,4+1):
    for j in range(i):
       print('*', end='')
    print()

hack

print('\n'.join(['*' * i for i in range(1, 4+1)])

Grouping adjacent

grouping adjacent use zip and iter...
some code like this:

lst  = range(10)
group_n = lambda lst, n: zip(*([iter(lst)] * n))
print group(lst, 3)
#output
#[(0, 1, 2), (3, 4, 5), (6, 7, 8)]

characters_occurrence.py

! /usr/bin/env python3

"""To find the number of times characters are repeated in a string """

from collections import Counter

Counter('abracadabra').most_common(3)

[('a', 5), ('r', 2), ('b', 2)]

The argument of most_common is the number of items to be returned

Default will return count for all characters

Counter('abracadabra').most_common(1)

[('a', 5)]

Is the repo dead?

I am asking because I am not seeing any response to PR's or issues for quite some time?

Any ideas guys?

Netsed if else

Traditional way

if a > 7:
    b = '>7'
elif a == 7:
    b = '7'
else:
    b = '<7'

hack

b = '>7' if a > 7 else '7' if a == 7 else '<7'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.