Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet458/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   454   455   456   457   458   459   460   461   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Method

Description

Example

seq.append(val)

Adds a single item to the end of

a list.


x = [True, False]

x.append(None)

# [True, False,

None]


seq.extend(vals)

Adds one or more items from a

collection onto the end of a list.

x = [1,2]

y = [3,4]

x.extend(y)

# x is [1, 2, 3, 4]

seq.count(val)

Counts the number of

occurrences of a given item.

x = [7,9,2,7,1]

x.count(7) # 2

seq.index(val, start,

end)

Determines the index of the



first occurrence of an item,

within an optional index range.

x = [7,9,2,7,1]

x.index(7) # 0

x.index(7,1) # 3

seq.insert(index,

val)

Inserts an item at a given



positional index within a list,

increasing the length of the list

by one.

x = [1,2,2,1]

x.insert(2,4)

# [1, 2, 4, 2, 1]

seq.pop(index)

Removes and passes back an

item from a list, reducing the

length of the list by one.

Defaults to remove the last

item, otherwise an index may

be specified.

x =


['a','b','c','d']

x.pop() # 'd'; x now

['a', 'b', 'c']

x.pop(1) # 'b'; x

now ['a', 'c']

seq.remove(val)

Removes the first occurrence of

an item from a list.

x = [1,2,3,2,1]

x.remove(2)

# [ 1, 3, 2, 1]

seq.reverse()

Reverses the order of items of

the list. Does not generate a

x =

['a','b','c','d']




new list.

x.reverse()

# ['d', 'c', 'b',

'a']


seq.sort(comparator,

key, reverse)

Above for Python 2

seq.sort(key,

reverse)

Above for Python 3

Sorts the items of a list, using

optional comparison function

(in Python 2) and key attribute.

Option to sort in reverse order.

x = [7,9,2,7,1]

x.sort()


# [1, 2, 7, 7, 9]

x.sort(reverse=True)

# [9, 7, 7, 2, 1]

Set operations

The  set  and  the  immutable  equivalent  frozenset  are  Python’s  standard  unordered  non-

repeating collection data types. The following table lists common operations and methods

for  sets  (and  where  appropriate  frozen  sets).  Sets  may  be  specified  with  the  inbuilt  set()

function,  operating  on  another  collection,  e.g.  set([a,b,c])  and  also  (from  Python  2.7

onwards) by using the curly brace notation {a,b,c}, which differs from dictionaries due to

the absence of colons. Using set() with no arguments or on an empty collection creates an

empty  set,  but  {}  does  not;  it  is  an  empty  dictionary.  For  the  descriptions  below  we  list

methods of sets in the form s.method(args) and also any equivalents that can be performed

with a symbolic operator syntax. For example, set3 = set1.union(set2) is equivalent to set3

= set1 | set2.


Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   454   455   456   457   458   459   460   461   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish