[TriLUG] OT-ish: Python array slicing question

David Brain via TriLUG trilug at trilug.org
Mon Dec 12 18:34:06 EST 2022


Steve,

For dicts use copy() (shallow) :
>>> a={'a':'ant','b':'bat','c':'cat'}
>>> b=a.copy()
>>> b['a']='antelope'
>>> a
{'a': 'ant', 'b': 'bat', 'c': 'cat'}
>>> b
{'a': 'antelope', 'b': 'bat', 'c': 'cat'}

David.

On Mon, Dec 12, 2022 at 5:44 PM Steve Litt via TriLUG <trilug at trilug.org>
wrote:

> Steve Litt via TriLUG said on Mon, 12 Dec 2022 17:32:36 -0500
>
> >What's the best way of making a copy of a string?
>
> Oh neva-mind, mere assignment does the job for strings:
>
> ===================================
> #!/usr/bin/python3
> st1='st1'
> st2=st1
> st2='st2'
> print(st1)
> print(st2)
> ===================================
>
> Results:
>
> st1
> st2
>
> Thanks,
>
> SteveT
>
> Steve Litt
> Autumn 2022 featured book: Thriving in Tough Times
> http://www.troubleshooters.com/bookstore/thrive.htm
> --
> This message was sent to: dbrain at gmail.com <dbrain at gmail.com>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : https://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web  :
> https://www.trilug.org/mailman/options/trilug/dbrain%40gmail.com
> Welcome to TriLUG: https://trilug.org/welcome


More information about the TriLUG mailing list