Giter Site home page Giter Site logo

rs's Introduction

rs

Strings

Find

str1.find('x')          # find 'first' location of char x and return index
str1.rfind('x')         # find first int location of char x from reverse

Spllit

l = "0:start:0"
tokens = l.split(":")
print(tokens) # ['0', 'start', '0']

l= "How are you?"
tokens = l.split()
print(tokens) # ['How', 'are', 'you?']

List

create an list with 5 zeros

test = [0] * 5 # [0, 0, 0, 0, 0]

Append

new_list = []
new_list.append(1)
new_list.append(3)
# new_list [1, 3]

Reverser

ss = [1,2,3]
ss.reverse()
print(ss) #3,2,1

Join two lists

list1 = ["a", "b" , "c"]
list2 = [1, 2, 3]
list3 = list1 + list2 # ['a', 'b', 'c', 1, 2, 3]

Sort

a = ['Ford', 'BMW', 'Volvo']
print(a)  # ['Ford', 'BMW', 'Volvo']
a.sort()  
print(a)  # ['BMW', 'Ford', 'Volvo']  **a is sorted

#another way 
b = ['Ford', 'BMW', 'Volvo']
print(sorted(b)) # ['BMW', 'Ford', 'Volvo']
print(b)         # ['Ford', 'BMW', 'Volvo']  **b is not sorted

Dictionary

d = {'key': 'value'}         # Declare dict{'key': 'value'}
d['key'] = 'value'           # Add Key and Value
{x:0 for x in {'a', 'b'}}    # {'a': 0, 'b': 0} declare through comprehension 
d['key'])                    # Access value
d.items()                    # Items as tuple list dict_items([('key', 'value')])
if 'key' in d: print("meh")  # Check if value exists
par = {}
par.setdefault(1,1)          # returns 1, makes par = { 1 : 1 }
par = {0:True, 1:False}
par.pop(0)                   # Remove key 0, Returns True, par now {1: False}
for k in d: print(k)         # Iterate through keys

rs's People

Contributors

xiqifei avatar

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.