## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
Sundeep Agarwal
@learnbyexample
Hi there!
have a look at scripting course for intro material on Linux command line, Vim, Python and Perl
and also links for curated resources on these topics
Sundeep Agarwal
@learnbyexample
So, this doubt was asked during workshop and wasn't able to answer then
How to pop items in 2D lists in Python?
>>> list_2D = [[1, 3, 2, 10], [1.2, -0.2, 0, 2]]
>>> list_2D
[[1, 3, 2, 10], [1.2, -0.2, 0, 2]]
>>> list_2D[0].pop(0)
1
>>> list_2D
[[3, 2, 10], [1.2, -0.2, 0, 2]]

>>> list_2D.pop(1)
[1.2, -0.2, 0, 2]
>>> list_2D
[[3, 2, 10]]
Sundeep Agarwal
@learnbyexample
An interesting python exercise:
Given a list of numbers, it is easy to get max/min number using in-built functions
Write a function that accepts list as argument and returns 3rd lowest number from the list. The list can contain duplicate numbers.
Sundeep Agarwal
@learnbyexample

An easy way to get 2nd max, 3rd min, etc is to sort the input and then use indexing... since duplicates is a problem, remove them first...

>>> dup_nums = [-1, 2, 4.23, 2, 1, 2, 3.14, 1]
>>> sorted(dup_nums)
[-1, 1, 1, 2, 2, 2, 3.14, 4.23]
>>> sorted(set(dup_nums))
[-1, 1, 2, 3.14, 4.23]

then use indexing

>>> sorted(set(dup_nums))[2]
2
>>> sorted(set(dup_nums), reverse=True)[-3]
2
Sundeep Agarwal
@learnbyexample
Ashok Bakthavathsalam
@kgashok
Nice work, Sundeep.
Where are you based out of?
Sundeep Agarwal
@learnbyexample
Added a new Python exercise Q2d - https://github.com/learnbyexample/Python_Basics/blob/master/Exercises.md#functions
it is a feature that Perl provides by default - changing string to number where applicable...
so, the exercise here is about checking and returning if the string can be converted into int/float.. while solving, I also understood try-except better
try it out and post your solution here :)
Sundeep Agarwal
@learnbyexample

When I share Perl one-liners I'm often asked why use perl over sed/awk/etc...

perl borrows features/syntax from sed/awk/etc and has constructs primarily meant for cli usage... the main advantage over them being regular expression features, larger stdlib and various 3rd party modules.. also, if perl is available, it is better suited for portability across Linux/Mac/etc

some examples:

朱家华
@climberCN
Sundeep Agarwal
@learnbyexample
you're welcome @climberCN :)
Sundeep Agarwal
@learnbyexample
next chapter on cli text processing is ruby one-liners(https://github.com/learnbyexample/Command-line-text-processing/blob/master/ruby_one_liners.md)
first draft is almost complete.. overall, I liked the inbuilt methods.. many were similar to those I'm used to in python..
perl still wins over ruby in terms of made for cli usage --> implicit numeric conversions, auto-increment/decrement, regex syntax, etc
Sundeep Agarwal
@learnbyexample
so, I've done 6 revisions so far... lots of fixes/additions/improvements...
check out https://github.com/learnbyexample/Command-line-text-processing/blob/master/ruby_one_liners.md and let me know your feedback, thanks :)
Sundeep Agarwal
@learnbyexample
feeling good after waking up to know that ruby one-liners got featured in https://rubyweekly.com/issues/389 :)
Sundeep Agarwal
@learnbyexample
Did you know why chmod +w doesn't give write permission to other as well?
https://unix.stackexchange.com/questions/429421/why-chmod-w-filename-not-giving-write-permission-to-othero
Sundeep Agarwal
@learnbyexample
Finished porting #Python exercises to https://repl.it/community/classrooms/52626
test cases included, so your solution would be tested automatically.. additionally, you can submit them for review..
Happy coding :)
Sundeep Agarwal
@learnbyexample
look ma, 𝗯𝗼𝗹𝗱 𝘁𝗲𝘅𝘁
$echo 'hello!' | perl -CS -pe 'tr/a-z/\x{1d5ee}-\x{1d607}/' 𝗵𝗲𝗹𝗹𝗼!$ echo 'hello!' | ruby -pe '$_.tr!("a-z", "\u{1d5ee}-\u{1d607}")' 𝗵𝗲𝗹𝗹𝗼!$ echo 'Hi' | perl -CS -pe 'tr/a-zA-Z/\x{1d5ee}-\x{1d607}\x{1d5d4}-\x{1d5ed}/'
𝗛𝗶
Sundeep Agarwal
@learnbyexample
can also use the unicode characters themselves instead of hex value
$echo 'How are you?' | perl -Mopen=locale -Mutf8 -pe 'tr/a-zA-Z/𝗮-𝘇𝗔-𝗭/' 𝗛𝗼𝘄 𝗮𝗿𝗲 𝘆𝗼𝘂?$ echo 'I am good' | ruby -pe '\$_.tr!("a-zA-Z", "𝗮-𝘇𝗔-𝗭")'
𝗜 𝗮𝗺 𝗴𝗼𝗼𝗱
Sundeep Agarwal
@learnbyexample
if you think learning programming is taking long time:
Sundeep Agarwal
@learnbyexample

There are just too many curated lists about nice stuff out there.. such a pain to decide what I should add or not to curated resources repo

Enjoy these two:

Sundeep Agarwal
@learnbyexample
Sundeep Agarwal
@learnbyexample
Confused about start:stop:step slicing notation in Python?
https://stackoverflow.com/questions/509211/explain-pythons-slice-notation
Sundeep Agarwal
@learnbyexample
Sundeep Agarwal
@learnbyexample
Are you brave enough to read this 𝘁𝗶𝗱𝗯𝗶𝘁 of Unix/Linux shell history? https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then
heisenberg1977
@heisenberg1977
Looking at the command line text processing material. Are the files available? (e.g. marks_201*)
Sundeep Agarwal
@learnbyexample
@heisenberg1977 I plan to add them to the repos, but there are some issues and things like in-place editing messes up (I want to replace those examples among other todo stuff).. but I could help you out with specific files.. check your private chat from me.. :)
Sundeep Agarwal
@learnbyexample
Step by step guide to Ruby regular expressions: https://leanpub.com/rubyregexp
deepgrace
@deepgrace
Awesome Tetris in Bash https://github.com/deepgrace/tetris