Re: Two python issues

Liste des GroupesRevenir à cl python 
Sujet : Re: Two python issues
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 06. Nov 2024, 02:26:51
Autres entêtes
Organisation : Stefan Ram
Message-ID : <two-20241106011638@ram.dialup.fu-berlin.de>
References : 1
Raymond Boute <raymond.boute@pandora.be> wrote or quoted:
s[s.find('a')]
'p'

  If you want exceptions, index() is your jam.

Moreover, using index -1 for the last item is a bad choice: it should be
len(s) - 1 (no laziness!).

  This feature is the bee's knees, man.

last_item = my_list[ -1 ]
second_to_last = my_list[ -2 ]

  Way cleaner than my_list[ len( my_list )- 1 ], don't you think?

(b) When using assignment for slices, only lists with the same length as
the slice should be acceptable, otherwise an error should be given. 

  The current setup lets you pull off some seriously gnarly code
  maneuvers:

python
# Insert elements
my_list[ 2: 2 ]=[ 4, 5, 6 ]

# Replace a section
my_list[ 1: 4 ]=[ 10, 11 ]

# Delete elements
my_list[ 2: 5 ]= []

  These moves are slick and expressive. Forcing exact length
  matching would only cramp our style.

  Look, I get it. You're probably fresh out of coding bootcamp,
  thinking you can reinvent the wheel. But trust me, these features
  are solid gold. They're not perfect, sure, but they're about
  as good as finding a parking spot in San Francisco on a Saturday
  night. So before you go throwing shade at Python, maybe spend
  some more time with it. You might just find it grows on you like
  a NorCal redwood. Keep coding, and don't let the fog get you down!



Date Sujet#  Auteur
5 Nov 24 * Two python issues4Raymond Boute
5 Nov 24 +* Re: Two python issues2Piergiorgio Sartor
5 Nov 24 i`- Re: Two python issues (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
6 Nov 24 `- Re: Two python issues1Stefan Ram

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal