¡@

Home 

python Programming Glossary: len

How to generate all permutations of a list in Python

http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python

recipes 252178 def all_perms elements if len elements 1 yield elements else for perm in all_perms elements.. else for perm in all_perms elements 1 for i in range len elements #nb elements 0 1 works in both string and list contexts.. range 3 012 021 102 120 201 210 pool tuple iterable n len pool r n if r is None else r if r n return indices range n cycles..

Get last n lines of a file with Python, similar to tail

http://stackoverflow.com/questions/136168/get-last-n-lines-of-a-file-with-python-similar-to-tail

a n lines from f with an offset of offset lines. avg_line_length 74 to_read n offset while 1 try f.seek avg_line_length to_read.. 74 to_read n offset while 1 try f.seek avg_line_length to_read 2 except IOError # woops. apparently file is smaller.. instead f.seek 0 pos f.tell lines f.read .splitlines if len lines to_read or pos 0 return lines to_read offset and offset..

Fastest way to list all primes below N in python

http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python

def del_mult tk start step for k in xrange start len tk step tk k False # end of inner functions definition cpos.. # now complete for every other possible prime while pos len tk1 cpos const pos if tk1 pos p.append cpos 1 if tk7 pos p.append.. p.append cpos 29 pos 1 # remove exceeding if present pos len p 1 while p pos N pos 1 if pos len p 1 del p pos 1 # return..

How does zip(*[iter(s)]*n) work in Python?

http://stackoverflow.com/questions/2233204/how-does-zipitersn-work-in-python

7 8 9 # iterate over L in steps of 3 for start in range 0 len L chunk_size # xrange in 2.x range in 3.x end start chunk_size..

How do you split a list into evenly sized chunks in Python?

http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python

evenly sized chunks in Python I have a list of arbitrary length and I need to split it up into equal size chunks and operate.. if anyone had a good solution to this for lists of any length e.g. using generators. This should work l range 1 1000 print.. Yield successive n sized chunks from l. for i in xrange 0 len l n yield l i i n import pprint pprint.pprint list chunks range..

How can I represent an 'Enum' in Python?

http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python

on a project in Python. How can I represent the equivalent of an Enum in Python python enums share improve this question.. Enum Animal Enum 'Animal' 'ant bee cat dog' or equivalently class Animals Enum ant 1 bee 2 cat 3 dog 4 In earlier versions.. def enum sequential named enums dict zip sequential range len sequential named return type 'Enum' enums and used like so Numbers..

How to improve performance of this code?

http://stackoverflow.com/questions/4295799/how-to-improve-performance-of-this-code

'F' bCamel 'B' gap 'G' def solution formation return len i for i in formation formation.index fCamel 1 if i bCamel 0.. igap 0 genn igap igap 1 if igap 1 genn igap igap 2 if igap len formation 1 genn igap igap 1 if igap len formation 2 genn igap.. igap 2 if igap len formation 1 genn igap igap 1 if igap len formation 2 genn igap igap 2 return res class node def __init__..

What is the most “pythonic” way to iterate over a list in chunks?

http://stackoverflow.com/questions/434287/what-is-the-most-pythonic-way-to-iterate-over-a-list-in-chunks

Currently I'm iterating over it this way for i in xrange 0 len ints 4 # dummy op for example code foo ints i ints i 1 ints..

Rolling or sliding window iterator in Python

http://stackoverflow.com/questions/6822725/rolling-or-sliding-window-iterator-in-python

can be considered a special case where the window length is 1. I'm currently using the following code. Does anyone.. s1 s2 ... sn ... it iter seq result tuple islice it n if len result n yield result for elem in it result result 1 elem yield..

Tricky Logic Need help? [closed]

http://stackoverflow.com/questions/7436410/tricky-logic-need-help

' do nothing with these type I have tried using split If Len text x 7 And Len text x 1 2 Or Len text x 6 And Len text x 1.. these type I have tried using split If Len text x 7 And Len text x 1 2 Or Len text x 6 And Len text x 1 3 Then text x text.. tried using split If Len text x 7 And Len text x 1 2 Or Len text x 6 And Len text x 1 3 Then text x text x text x 1 ActiveSheet.Cells..