Skip to content

tarikwaleed/LeetCooding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Some cool hacks tricks i learned during my competitive programming journey

  • if you want to iterate n times and you don't want to use the iteration variable
for _ in '-' * n:
    print('a')

will print the letter 'a' n times , as well as

for _ in range(n):
    print('a')

to take n line of input as list of lists

list_of_lists = [input().split() for _ in '_' * n]
print(list_of_lists)
Output:
[[..,..],[..,..,..,..],[..,..]]

to unpack the list

print(*list_of_lists)
Output:
[..,..] [..,.., .., ..] [..,..]

Trick from CF268-D2-A

suppose you have the followint input:

3

1 2

3 4

5 6

the first line of input is n .

the following line of code takes the input as rows and then convert them to colums using zip():

a, b = zip(*(input().split() for _ in '_' * n))

a=[1,3,5]

b=[2,4,6]

About

My solutions to some of code forces problems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages